C-PROJECT | FLIGHT BOOKING SYSTEM | WORKING CODE & DOWNLOADABLE
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
//Global Variables
char programmer[]="Narendra A";
char course[]="B.C.A.";
char college[]="Pragati Computers";
int roll1=1;
int roll2=2;
char projectTitle[]="Flight Booking System";
char password[]="password";
char airports[][20]={"Mumbai","Delhi","Kolkatta","Chennai","Ahmedabad","Surat","Pune","U.P.","M.P.","Goa"};
//Functions prototyping
void adminMenu(); //Options avaialble for admin
void adminChoice();
void guestMenu(); //Options available for guest
void guestChoice();
void Login(); //Function for Login to Admin Menu
void project();
void boardingPass(); //For Create Boarding Pass
void showSeats(); //Function to display the seats of flight
void searchFlight();
void drawLine(); //function to draw a single line for presentation
void frame(); //Displaying the header & footer
void sideframe(); //Displaying the side frames
void top(); //Setting the top position to print from
void loading(); //Loading process
void programmers(); //About Programmers
void acknowledge(); //About Project.
//Defination of Structure : Flight
struct Flight
{
int FlightNo; //Unique Flight No.
char source[20]; //Source Airport From
char destination[20]; //Destination Flight Upto
int bizSeats; //3 Rows and 4 Columns of seats for Business Class Seats
int ecoSeats; //7 Rows and 6 Columns of seats for Economic Class Seats
float ecoFare; //Airfare for Economic Class Seats
float bizFare; //Airfare for Business Class Seats
}F;
//Defination of Structure : Booking
struct Booking
{
int num;
char firstname[15];
char lastname[15];
char address[60];
char src[20];
char destn[20];
char type[30];
int Seats;
int catogary;
float amount;
}B;
//Function to take input for Flight Data File by Admin only
void getData()
{
system("cls");
FILE *p;
int ch1,ch2,i;
p=fopen("flight.dat","a");
printf("Enter The Flight Information\n");
printf("\tFlight Number: ");
scanf("%d",&F.FlightNo);
selectSource: //Label Declared
system("cls");
printf("Select Source from below airports\n");
for(i=0;i<10;i++)
{
printf("%2d. %-16s",i+1,airports[i]);
}
printf("\nEnter number of your choice: ");
scanf("%d",&ch1);
if(ch1>=1 && ch1<=10)
switch(ch1)
{
case 1: strcpy(F.source,"Mumbai"); break;
case 2: strcpy(F.source,"Delhi"); break;
case 3: strcpy(F.source,"Kolkatta"); break;
case 4: strcpy(F.source,"Chennai"); break;
case 5: strcpy(F.source,"Ahmedabad"); break;
case 6: strcpy(F.source,"Surat"); break;
case 7: strcpy(F.source,"Pune"); break;
case 8: strcpy(F.source,"U.P."); break;
case 9: strcpy(F.source,"M.P."); break;
case 10: strcpy(F.source,"Goa"); break;
}
selectDestination: //Label Declared
printf("\nSelect Destination from below airports\n");
for(i=0;i<10;i++)
{
printf("%2d. %-16s",i+1,airports[i]);
}
printf("\nEnter number of your choice: ");
scanf("%d",&ch2);
if(ch2==ch1)
{
printf("The Source & Destination should not be same.\nKindly reselect properly.\n");
goto selectDestination;
}
else
switch(ch2)
{
case 1: strcpy(F.destination,"Mumbai"); break;
case 2: strcpy(F.destination,"Delhi"); break;
case 3: strcpy(F.destination,"Kolkatta"); break;
case 4: strcpy(F.destination,"Chennai"); break;
case 5: strcpy(F.destination,"Ahmedabad"); break;
case 6: strcpy(F.destination,"Surat"); break;
case 7: strcpy(F.destination,"Pune"); break;
case 8: strcpy(F.destination,"U.P."); break;
case 9: strcpy(F.destination,"M.P."); break;
case 10: strcpy(F.destination,"Goa"); break;
}
F.bizSeats=12;
F.ecoSeats=42;
printf("\tEconomy Class Fare : ");
scanf("%f",&F.ecoFare);
F.bizFare=F.ecoFare*4;
fprintf(p,"%d %s %s %d %d %f %f\n",F.FlightNo,F.source,F.destination,F.bizSeats,F.ecoSeats,F.ecoFare,F.bizFare);
fclose(p);
}
//Function to show data of Flight Data File by Admin only
void showData()
{
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
for(int i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
delay(300);
}
void listTitle()
{
int i;
printf("%-10s","Flight #");
printf("%-12s","Source");
printf("%-12s","Destination");
printf("%-10s","B.Seats");
printf("%-10s","E.Seats");
printf("%-10s","B.Fare");
printf("%-10s","E.Fare");
printf("\n");
for(i=1;i<=72;i++)
{
printf("=");
}
printf("\n");
}
void listData()
{
int i;
FILE *p;
p=fopen("flight.dat","r");
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
for(i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
delay(300);
}
fclose(p);
}
void menu()
{
int ch;
do
{
system("cls");
printf("FLIGHT OPERATION MENU\n");
printf("=====================\n");
printf("0. Exit\n");
printf("1. Register New Flight Info\n");
printf("2. Show Flight Details\n");
printf("3. Search Flight\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: getData(); break;
case 2: listData(); break;
case 3: searchFlight(); break;
}
system("pause");
}while(ch);
}
void searchFlight()
{
int ch, flag=0, n, i;
char stn[20];
FILE *p;
p=fopen("flight.dat","r");
printf("\nSearch Flight Options");
printf("\n=====================\n");
printf("\n1. By Flight Number");
printf("\n2. By Destination");
printf("\n\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the Flight No.: ");
scanf("%d",&n);
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(n==F.FlightNo)
{
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
flag++;
for(i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
}
}
break;
case 2:
printf("\nEnter name of Airport : ");
fflush(stdin);
gets(stn);
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(strcmpi(stn,F.source)==0 || strcmpi(stn,F.destination)==0)
{
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
flag++;
for(i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
}
}
break;
}
if(flag==0)
printf("\nSearch criteria not found....\n");
printf("\nFile Reading completed...\n");
fclose(p);
}
void programmers()
{
clrscr();
int row=4, col=5;
frame();
textcolor(10);
gotoxy(col+25,row++);
cprintf("ABOUT PROGRAMMERS");
gotoxy(col,row++);
gotoxy(col,row++);
textcolor(5);
cprintf("Name : 1. Narendra A.");
gotoxy(col,row++);
cprintf(" 2. Narendra A.");
gotoxy(col,row++);
cprintf("Roll # : 1. 301");
gotoxy(col,row++);
cprintf(" 2. 302 ");
gotoxy(col,row++);
cprintf("Class : B.C.A.");
gotoxy(col,row++);
cprintf("Sem. : IV");
gotoxy(col,row++);
cprintf("Ac.Yr. : 2018-19");
gotoxy(col,row++);
cprintf("Dept. : Comp. Sci.");
gotoxy(col,row++);
cprintf("Guide : Pr. XXXXXXXXXXXX");
gotoxy(col,row++);
cprintf("H.O.D. : Pr. xxxxxxxxxxxx");
gotoxy(col,row++);
cprintf("Univ. : xxxxxxxx University");
textcolor(7);
getch();
}
void acknowledge()
{
clrscr();
int row=3, col=5;
frame();
textcolor(11);
gotoxy(col+25,row++);
cprintf("ABOUT PROJECT");
textcolor(14);
gotoxy(col,row++);
cprintf("This project of airline tickets booking, which include 2\n");
gotoxy(col,row++);
cprintf("sections namely Admin and Guest. For Admin Login, it is ");
gotoxy(col,row++);
cprintf("protected with authorization and Guest is open for all.");
gotoxy(col,row++);
cprintf("Under Guest menu certain options are given for");
gotoxy(col,row++);
cprintf("booking and viewing the flights.");
gotoxy(col,row++);
cprintf("The project also saves the data in the");
gotoxy(col,row++);
cprintf("binary file format and also generate the");
gotoxy(col,row++);
cprintf("boarding pass of the passenger.");
gotoxy(col,row++);
cprintf("More about the project can be experienced");
gotoxy(col,row++);
cprintf("through from the main menu of the project.");
gotoxy(col,row++);
cprintf("We the programmers, would like to acknowledge our");
gotoxy(col,row++);
cprintf("sincere thanks to our Project Guide and H.O.D. of");
gotoxy(col,row++);
cprintf("the department, who trained us and motivated us");
gotoxy(col,row++);
cprintf("to do this project.");
gotoxy(col,row+=2);
cprintf("Sincere regards.");
textcolor(7);
getch();
}
void loading()
{
int j;
clrscr();
gotoxy(15,12);
printf("Wait a Minute! Your Boarding Pass is getting Ready!");
gotoxy(1,14);
for(j=1;j<=80;j++)
{
gotoxy(j,14);
printf("%c",196);
}
for(j=1;j<=80;j++)
{
gotoxy(j,16);
printf("%c",196);
}
for(j=2;j<=79;j++)
{
gotoxy(j,15);
printf("%c",219);
delay(50);
}
printf("\n\n\nEnter Any Key To continue..");
getch();
}
//Function to take input for Flight Data by Customer
void getTicket()
{
int temp=0,no;
float price;
FILE *p,*t;
clrscr();
p=fopen("flight.dat","r");
t=fopen("Customer.dat","a");
int ch;
frame();
top();
printf("\tEnter The Flight Information\n");
printf("\tSource : ");
scanf("%s",B.src);
printf("\tDestination : ");
scanf("%s",B.destn);
clrscr();
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if((strcmpi(B.src,F.source)==0) && (strcmpi(B.destn,F.destination)==0))
{
showData();
temp++;
}
}
fclose(p);
if(temp==0)
{
printf("Flight Not Found");
getch();
return;
}
temp=0;
SelNum:
printf("\nEnter Flight Number from the above list to Select Flight :");
scanf("%d",&no);
printf("\tSeat Type\n");
printf("\t1. Business Class\n");
printf("\t2. Economy Class\n");
printf("\tSelect Seat Type: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
biz:
showSeats();
gotoxy(20,18);
textcolor(12);
cprintf("Select Seat # from Business Class : ");
textcolor(7);
scanf("%d",&B.catogary);
strcpy(B.type,"Business");
if(B.catogary<1 || B.catogary>12)
{
gotoxy(20,20);
textcolor(12);
cprintf("Select Seat No. between 1 to 12 only");
textcolor(7);
getch();
goto biz;
}
else
{
p=fopen("flight.dat","r");
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(no==F.FlightNo)
{
price=F.bizFare;
}
}
fclose(p);
}
break;
case 2:
eco:
showSeats();
gotoxy(20,18);
textcolor(12);
cprintf("Select Seat # from Economic Class : ");
textcolor(7);
scanf("%d",&B.catogary);
strcpy(B.type,"Economic");
if(B.catogary<12 || B.catogary>54)
{
gotoxy(20,20);
textcolor(12);
cprintf("Select Seat No. between 12 to 54 only");
textcolor(7);
getch();
goto eco;
}
else
{
p=fopen("flight.dat","r");
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(no==F.FlightNo)
{
price=F.ecoFare;
}
}
fclose(p);
}
break;
}
clrscr();
printf("Enter First Name :");
scanf("%s",B.firstname);
printf("Enter Last Name :");
scanf("%s",B.lastname);
printf("Enter Address :");
fflush(stdin);
gets(B.address);
printf("Enter Number of Seats :");
scanf("%d",&B.Seats);
B.amount=B.Seats*price;
fprintf(t,"%s %s %s %d %s %s %d %f\n",B.src,B.destn,B.type,B.Seats,B.firstname,B.lastname,B.Seats,B.amount);
loading();
boardingPass();
fclose(t);
getch();
}
void boardingPass()
{
clrscr();
drawLine();
printf("%40s","ABCD Airlines\n");
drawLine();
printf("Source : %-12s\n",B.src);
printf("Destination : %-12s\n",B.destn);
printf("Class : %-12s\n",B.type);
printf("No.of Seats : %-10d\n",B.Seats);
drawLine();
printf("Name :%-12s %-12s\n\n",B.firstname,B.lastname);
drawLine();
printf("Total Pay : %-10.2f\n",B.amount);
drawLine();
printf("Status: Varified and Not Cancellation\n");
drawLine();
}
//Presentation Functions
void drawLine()
{
int i;
textcolor(14);
for(i=1;i<=79;i++)
cprintf("=");
textcolor(7);
printf("\n");
}
void frame()
{
//Header Line Contents & Setting
sideframe();
textcolor(7);
gotoxy(1,1);
drawLine();
gotoxy(30,2);
textcolor(10);
cprintf("%s",projectTitle);
textcolor(7);
gotoxy(1,3);
drawLine();
//Footer Line Contents & Setting
gotoxy(1,23);
drawLine();
gotoxy(1,24);
textcolor(2);
cprintf("By: %s ",programmer);
textcolor(3);
cprintf("Course: %s ",course);
textcolor(4);
cprintf("Roll No.: %d & %d ",roll2, roll1);
textcolor(5);
cprintf("College: %s",college);
gotoxy(1,25);
drawLine();
gotoxy(4,4);
textcolor(7);
}
void sideframe()
{
int x, y;
//Left & Right Line
for(y=4; y<=22; y++)
{
textcolor(14);
x=1;
gotoxy(x,y);
cprintf("|");
x=79;
gotoxy(x,y);
cprintf("|");
textcolor(7);
}
textcolor(7);
}
void top()
{
gotoxy(4,4);
textcolor(7);
}
//show Seats Function
void showSeats()
{
clrscr();
frame();
int row=4, col=20, i, j, s=1;
gotoxy(col+10,row);
textbackground(15);
textcolor(0);
cprintf("BUSINESS CLASS SEAT #");
textbackground(0);
row+=1;
for(i=0;i<3;i++)
{
gotoxy(col,row);
textcolor(12);
cprintf("Row%2d ",i+1);
for(j=0;j<4;j++)
{
textcolor(14);
cprintf("%6d",s++);
if(j==1) printf("\t");
}
printf("\n");
row+=1;
}
row+=1;
gotoxy(col+10,row);
textbackground(15);
textcolor(0);
cprintf("ECONOMY CLASS SEAT #");
row+=1;
textbackground(0);
for(i=3;i<10;i++)
{
gotoxy(col,row);
textcolor(10);
cprintf("Row%2d ",i);
for(j=0;j<6;j++)
{
textcolor(14);
cprintf("%4d",s++);
if(j==2) printf("\t");
}
printf("\n");
row+=1;
}
gotoxy(col,row);
textcolor(7);
}
//Authentication Function
void Login()
{
int i=0;
char verify[10];
char ch;
clrscr();
frame();
gotoxy(20,10);
getPass:
printf("Enter Login Password : ");
do
{
ch=getch();
if(ch!=13)
{
verify[i++]=ch;
printf("*");
}
else
{
verify[i++]='\0';
}
}while(ch!=13); //13 IS THE ASCII OF ENTER
gotoxy(20,14);
if(strcmp(password,verify)==0)
{
printf("Password Matched...");
getch();
adminChoice();
}
else
{
printf("Wrong Password...");
getch();
}
gotoxy(21,15);
}
//Admin Menu Display
void adminMenu()
{
frame();
int row=5, col=35;
gotoxy(col,row);
textcolor(11);
cprintf("ADMIN MENU");
gotoxy(col-1,row+1);
textcolor(3);
cprintf("============");
row+=2, col=25;
gotoxy(col,row);
textcolor(9);
cprintf("0. Back to Main Menu");
row+=2, col=25;
gotoxy(col,row);
textcolor(10);
cprintf("1. Register New Flight");
row+=2, col=25;
gotoxy(col,row);
textcolor(12);
cprintf("2. Show Registered Flights");
row+=2, col=25;
gotoxy(col,row);
textcolor(13);
cprintf("3. Search Flight");
row+=2, col=25;
gotoxy(col,row);
textcolor(14);
row+=2, col=28;
gotoxy(col,row);
textcolor(15);
cprintf("Enter your choice: ");
getch();
textcolor(7);
}
void adminChoice()
{
int ch;
do
{
clrscr();
adminMenu();
scanf("%d",&ch);
clrscr();
switch(ch)
{
case 1: getData();
break;
case 2: listData();
break;
case 3: searchFlight();
break;
}
getch();
}while(ch);
}
void guestMenu()
{
frame();
int row=5, col=35;
gotoxy(col,row);
textcolor(14);
cprintf("GUEST MENU");
gotoxy(col-1,row+1);
textcolor(4);
cprintf("============");
row+=2, col=25;
gotoxy(col,row);
textcolor(13);
cprintf("0. Back to Main Menu");
row+=2, col=25;
gotoxy(col,row);
textcolor(12);
cprintf("1. Book Ticket");
row+=2, col=25;
gotoxy(col,row);
textcolor(11);
cprintf("2. View Flights");
row+=2, col=25;
gotoxy(col,row);
textcolor(10);
cprintf("3. Show Seats Layout");
row+=2, col=25;
gotoxy(col,row);
textcolor(9);
row+=2, col=28;
gotoxy(col,row);
textcolor(15);
cprintf("Enter your choice: ");
textcolor(7);
}
void guestChoice()
{
int ch;
do
{
clrscr();
guestMenu();
scanf("%d",&ch);
switch(ch)
{
case 1: getTicket(); break;
case 2: clrscr(); listData(); getch(); break;
case 3: showSeats(); getch(); break;
}
}while(ch);
}
void project()
{
int ch;
do
{
int row=5, col=35;
clrscr();
textcolor(7);
frame();
gotoxy(col-5,row);
textcolor(10);
cprintf("M A I N M E N U");
gotoxy(col-7,row+1);
textcolor(3);
cprintf("=====================");
row+=2, col=25;
gotoxy(col,row);
textcolor(11);
cprintf("0. Exit");
row+=2, col=25;
gotoxy(col,row);
textcolor(12);
cprintf("1. ADMIN MENU");
row+=2, col=25;
gotoxy(col,row);
textcolor(13);
cprintf("2. GUEST MENU");
row+=2, col=25;
gotoxy(col,row);
textcolor(14);
cprintf("3. ABOUT PROJECT");
row+=2, col=25;
gotoxy(col,row);
textcolor(8);
cprintf("4. ABOUT MYSELF");
row+=2, col=28;
gotoxy(col,row);
textcolor(15);
cprintf("Enter your choice: ");
textcolor(7);
scanf("%d",&ch);
switch(ch)
{
case 1: Login(); break;
case 2: guestChoice(); break;
case 3: acknowledge(); break;
case 4: programmers(); break;
}
}while(ch);
textcolor(7);
}
void main()
{
clrscr();
project();
getch();
}
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
//Global Variables
char programmer[]="Narendra A";
char course[]="B.C.A.";
char college[]="Pragati Computers";
int roll1=1;
int roll2=2;
char projectTitle[]="Flight Booking System";
char password[]="password";
char airports[][20]={"Mumbai","Delhi","Kolkatta","Chennai","Ahmedabad","Surat","Pune","U.P.","M.P.","Goa"};
//Functions prototyping
void adminMenu(); //Options avaialble for admin
void adminChoice();
void guestMenu(); //Options available for guest
void guestChoice();
void Login(); //Function for Login to Admin Menu
void project();
void boardingPass(); //For Create Boarding Pass
void showSeats(); //Function to display the seats of flight
void searchFlight();
void drawLine(); //function to draw a single line for presentation
void frame(); //Displaying the header & footer
void sideframe(); //Displaying the side frames
void top(); //Setting the top position to print from
void loading(); //Loading process
void programmers(); //About Programmers
void acknowledge(); //About Project.
//Defination of Structure : Flight
struct Flight
{
int FlightNo; //Unique Flight No.
char source[20]; //Source Airport From
char destination[20]; //Destination Flight Upto
int bizSeats; //3 Rows and 4 Columns of seats for Business Class Seats
int ecoSeats; //7 Rows and 6 Columns of seats for Economic Class Seats
float ecoFare; //Airfare for Economic Class Seats
float bizFare; //Airfare for Business Class Seats
}F;
//Defination of Structure : Booking
struct Booking
{
int num;
char firstname[15];
char lastname[15];
char address[60];
char src[20];
char destn[20];
char type[30];
int Seats;
int catogary;
float amount;
}B;
//Function to take input for Flight Data File by Admin only
void getData()
{
system("cls");
FILE *p;
int ch1,ch2,i;
p=fopen("flight.dat","a");
printf("Enter The Flight Information\n");
printf("\tFlight Number: ");
scanf("%d",&F.FlightNo);
selectSource: //Label Declared
system("cls");
printf("Select Source from below airports\n");
for(i=0;i<10;i++)
{
printf("%2d. %-16s",i+1,airports[i]);
}
printf("\nEnter number of your choice: ");
scanf("%d",&ch1);
if(ch1>=1 && ch1<=10)
switch(ch1)
{
case 1: strcpy(F.source,"Mumbai"); break;
case 2: strcpy(F.source,"Delhi"); break;
case 3: strcpy(F.source,"Kolkatta"); break;
case 4: strcpy(F.source,"Chennai"); break;
case 5: strcpy(F.source,"Ahmedabad"); break;
case 6: strcpy(F.source,"Surat"); break;
case 7: strcpy(F.source,"Pune"); break;
case 8: strcpy(F.source,"U.P."); break;
case 9: strcpy(F.source,"M.P."); break;
case 10: strcpy(F.source,"Goa"); break;
}
selectDestination: //Label Declared
printf("\nSelect Destination from below airports\n");
for(i=0;i<10;i++)
{
printf("%2d. %-16s",i+1,airports[i]);
}
printf("\nEnter number of your choice: ");
scanf("%d",&ch2);
if(ch2==ch1)
{
printf("The Source & Destination should not be same.\nKindly reselect properly.\n");
goto selectDestination;
}
else
switch(ch2)
{
case 1: strcpy(F.destination,"Mumbai"); break;
case 2: strcpy(F.destination,"Delhi"); break;
case 3: strcpy(F.destination,"Kolkatta"); break;
case 4: strcpy(F.destination,"Chennai"); break;
case 5: strcpy(F.destination,"Ahmedabad"); break;
case 6: strcpy(F.destination,"Surat"); break;
case 7: strcpy(F.destination,"Pune"); break;
case 8: strcpy(F.destination,"U.P."); break;
case 9: strcpy(F.destination,"M.P."); break;
case 10: strcpy(F.destination,"Goa"); break;
}
F.bizSeats=12;
F.ecoSeats=42;
printf("\tEconomy Class Fare : ");
scanf("%f",&F.ecoFare);
F.bizFare=F.ecoFare*4;
fprintf(p,"%d %s %s %d %d %f %f\n",F.FlightNo,F.source,F.destination,F.bizSeats,F.ecoSeats,F.ecoFare,F.bizFare);
fclose(p);
}
//Function to show data of Flight Data File by Admin only
void showData()
{
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
for(int i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
delay(300);
}
void listTitle()
{
int i;
printf("%-10s","Flight #");
printf("%-12s","Source");
printf("%-12s","Destination");
printf("%-10s","B.Seats");
printf("%-10s","E.Seats");
printf("%-10s","B.Fare");
printf("%-10s","E.Fare");
printf("\n");
for(i=1;i<=72;i++)
{
printf("=");
}
printf("\n");
}
void listData()
{
int i;
FILE *p;
p=fopen("flight.dat","r");
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
for(i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
delay(300);
}
fclose(p);
}
void menu()
{
int ch;
do
{
system("cls");
printf("FLIGHT OPERATION MENU\n");
printf("=====================\n");
printf("0. Exit\n");
printf("1. Register New Flight Info\n");
printf("2. Show Flight Details\n");
printf("3. Search Flight\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: getData(); break;
case 2: listData(); break;
case 3: searchFlight(); break;
}
system("pause");
}while(ch);
}
void searchFlight()
{
int ch, flag=0, n, i;
char stn[20];
FILE *p;
p=fopen("flight.dat","r");
printf("\nSearch Flight Options");
printf("\n=====================\n");
printf("\n1. By Flight Number");
printf("\n2. By Destination");
printf("\n\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the Flight No.: ");
scanf("%d",&n);
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(n==F.FlightNo)
{
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
flag++;
for(i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
}
}
break;
case 2:
printf("\nEnter name of Airport : ");
fflush(stdin);
gets(stn);
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(strcmpi(stn,F.source)==0 || strcmpi(stn,F.destination)==0)
{
printf("%-10d",F.FlightNo);
printf("%-12s",F.source);
printf("%-12s",F.destination);
printf("%-10d",F.bizSeats);
printf("%-10d",F.ecoSeats);
printf("%-10.2f",F.bizFare);
printf("%-10.2f",F.ecoFare);
printf("\n");
flag++;
for(i=1;i<=72;i++)
{
printf("-");
}
printf("\n");
}
}
break;
}
if(flag==0)
printf("\nSearch criteria not found....\n");
printf("\nFile Reading completed...\n");
fclose(p);
}
void programmers()
{
clrscr();
int row=4, col=5;
frame();
textcolor(10);
gotoxy(col+25,row++);
cprintf("ABOUT PROGRAMMERS");
gotoxy(col,row++);
gotoxy(col,row++);
textcolor(5);
cprintf("Name : 1. Narendra A.");
gotoxy(col,row++);
cprintf(" 2. Narendra A.");
gotoxy(col,row++);
cprintf("Roll # : 1. 301");
gotoxy(col,row++);
cprintf(" 2. 302 ");
gotoxy(col,row++);
cprintf("Class : B.C.A.");
gotoxy(col,row++);
cprintf("Sem. : IV");
gotoxy(col,row++);
cprintf("Ac.Yr. : 2018-19");
gotoxy(col,row++);
cprintf("Dept. : Comp. Sci.");
gotoxy(col,row++);
cprintf("Guide : Pr. XXXXXXXXXXXX");
gotoxy(col,row++);
cprintf("H.O.D. : Pr. xxxxxxxxxxxx");
gotoxy(col,row++);
cprintf("Univ. : xxxxxxxx University");
textcolor(7);
getch();
}
void acknowledge()
{
clrscr();
int row=3, col=5;
frame();
textcolor(11);
gotoxy(col+25,row++);
cprintf("ABOUT PROJECT");
textcolor(14);
gotoxy(col,row++);
cprintf("This project of airline tickets booking, which include 2\n");
gotoxy(col,row++);
cprintf("sections namely Admin and Guest. For Admin Login, it is ");
gotoxy(col,row++);
cprintf("protected with authorization and Guest is open for all.");
gotoxy(col,row++);
cprintf("Under Guest menu certain options are given for");
gotoxy(col,row++);
cprintf("booking and viewing the flights.");
gotoxy(col,row++);
cprintf("The project also saves the data in the");
gotoxy(col,row++);
cprintf("binary file format and also generate the");
gotoxy(col,row++);
cprintf("boarding pass of the passenger.");
gotoxy(col,row++);
cprintf("More about the project can be experienced");
gotoxy(col,row++);
cprintf("through from the main menu of the project.");
gotoxy(col,row++);
cprintf("We the programmers, would like to acknowledge our");
gotoxy(col,row++);
cprintf("sincere thanks to our Project Guide and H.O.D. of");
gotoxy(col,row++);
cprintf("the department, who trained us and motivated us");
gotoxy(col,row++);
cprintf("to do this project.");
gotoxy(col,row+=2);
cprintf("Sincere regards.");
textcolor(7);
getch();
}
void loading()
{
int j;
clrscr();
gotoxy(15,12);
printf("Wait a Minute! Your Boarding Pass is getting Ready!");
gotoxy(1,14);
for(j=1;j<=80;j++)
{
gotoxy(j,14);
printf("%c",196);
}
for(j=1;j<=80;j++)
{
gotoxy(j,16);
printf("%c",196);
}
for(j=2;j<=79;j++)
{
gotoxy(j,15);
printf("%c",219);
delay(50);
}
printf("\n\n\nEnter Any Key To continue..");
getch();
}
//Function to take input for Flight Data by Customer
void getTicket()
{
int temp=0,no;
float price;
FILE *p,*t;
clrscr();
p=fopen("flight.dat","r");
t=fopen("Customer.dat","a");
int ch;
frame();
top();
printf("\tEnter The Flight Information\n");
printf("\tSource : ");
scanf("%s",B.src);
printf("\tDestination : ");
scanf("%s",B.destn);
clrscr();
listTitle();
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if((strcmpi(B.src,F.source)==0) && (strcmpi(B.destn,F.destination)==0))
{
showData();
temp++;
}
}
fclose(p);
if(temp==0)
{
printf("Flight Not Found");
getch();
return;
}
temp=0;
SelNum:
printf("\nEnter Flight Number from the above list to Select Flight :");
scanf("%d",&no);
printf("\tSeat Type\n");
printf("\t1. Business Class\n");
printf("\t2. Economy Class\n");
printf("\tSelect Seat Type: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
biz:
showSeats();
gotoxy(20,18);
textcolor(12);
cprintf("Select Seat # from Business Class : ");
textcolor(7);
scanf("%d",&B.catogary);
strcpy(B.type,"Business");
if(B.catogary<1 || B.catogary>12)
{
gotoxy(20,20);
textcolor(12);
cprintf("Select Seat No. between 1 to 12 only");
textcolor(7);
getch();
goto biz;
}
else
{
p=fopen("flight.dat","r");
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(no==F.FlightNo)
{
price=F.bizFare;
}
}
fclose(p);
}
break;
case 2:
eco:
showSeats();
gotoxy(20,18);
textcolor(12);
cprintf("Select Seat # from Economic Class : ");
textcolor(7);
scanf("%d",&B.catogary);
strcpy(B.type,"Economic");
if(B.catogary<12 || B.catogary>54)
{
gotoxy(20,20);
textcolor(12);
cprintf("Select Seat No. between 12 to 54 only");
textcolor(7);
getch();
goto eco;
}
else
{
p=fopen("flight.dat","r");
while(!feof(p))
{
fscanf(p,"%d %s %s %d %d %f %f\n",&F.FlightNo,F.source,F.destination,&F.bizSeats,&F.ecoSeats,&F.ecoFare,&F.bizFare);
if(no==F.FlightNo)
{
price=F.ecoFare;
}
}
fclose(p);
}
break;
}
clrscr();
printf("Enter First Name :");
scanf("%s",B.firstname);
printf("Enter Last Name :");
scanf("%s",B.lastname);
printf("Enter Address :");
fflush(stdin);
gets(B.address);
printf("Enter Number of Seats :");
scanf("%d",&B.Seats);
B.amount=B.Seats*price;
fprintf(t,"%s %s %s %d %s %s %d %f\n",B.src,B.destn,B.type,B.Seats,B.firstname,B.lastname,B.Seats,B.amount);
loading();
boardingPass();
fclose(t);
getch();
}
void boardingPass()
{
clrscr();
drawLine();
printf("%40s","ABCD Airlines\n");
drawLine();
printf("Source : %-12s\n",B.src);
printf("Destination : %-12s\n",B.destn);
printf("Class : %-12s\n",B.type);
printf("No.of Seats : %-10d\n",B.Seats);
drawLine();
printf("Name :%-12s %-12s\n\n",B.firstname,B.lastname);
drawLine();
printf("Total Pay : %-10.2f\n",B.amount);
drawLine();
printf("Status: Varified and Not Cancellation\n");
drawLine();
}
//Presentation Functions
void drawLine()
{
int i;
textcolor(14);
for(i=1;i<=79;i++)
cprintf("=");
textcolor(7);
printf("\n");
}
void frame()
{
//Header Line Contents & Setting
sideframe();
textcolor(7);
gotoxy(1,1);
drawLine();
gotoxy(30,2);
textcolor(10);
cprintf("%s",projectTitle);
textcolor(7);
gotoxy(1,3);
drawLine();
//Footer Line Contents & Setting
gotoxy(1,23);
drawLine();
gotoxy(1,24);
textcolor(2);
cprintf("By: %s ",programmer);
textcolor(3);
cprintf("Course: %s ",course);
textcolor(4);
cprintf("Roll No.: %d & %d ",roll2, roll1);
textcolor(5);
cprintf("College: %s",college);
gotoxy(1,25);
drawLine();
gotoxy(4,4);
textcolor(7);
}
void sideframe()
{
int x, y;
//Left & Right Line
for(y=4; y<=22; y++)
{
textcolor(14);
x=1;
gotoxy(x,y);
cprintf("|");
x=79;
gotoxy(x,y);
cprintf("|");
textcolor(7);
}
textcolor(7);
}
void top()
{
gotoxy(4,4);
textcolor(7);
}
//show Seats Function
void showSeats()
{
clrscr();
frame();
int row=4, col=20, i, j, s=1;
gotoxy(col+10,row);
textbackground(15);
textcolor(0);
cprintf("BUSINESS CLASS SEAT #");
textbackground(0);
row+=1;
for(i=0;i<3;i++)
{
gotoxy(col,row);
textcolor(12);
cprintf("Row%2d ",i+1);
for(j=0;j<4;j++)
{
textcolor(14);
cprintf("%6d",s++);
if(j==1) printf("\t");
}
printf("\n");
row+=1;
}
row+=1;
gotoxy(col+10,row);
textbackground(15);
textcolor(0);
cprintf("ECONOMY CLASS SEAT #");
row+=1;
textbackground(0);
for(i=3;i<10;i++)
{
gotoxy(col,row);
textcolor(10);
cprintf("Row%2d ",i);
for(j=0;j<6;j++)
{
textcolor(14);
cprintf("%4d",s++);
if(j==2) printf("\t");
}
printf("\n");
row+=1;
}
gotoxy(col,row);
textcolor(7);
}
//Authentication Function
void Login()
{
int i=0;
char verify[10];
char ch;
clrscr();
frame();
gotoxy(20,10);
getPass:
printf("Enter Login Password : ");
do
{
ch=getch();
if(ch!=13)
{
verify[i++]=ch;
printf("*");
}
else
{
verify[i++]='\0';
}
}while(ch!=13); //13 IS THE ASCII OF ENTER
gotoxy(20,14);
if(strcmp(password,verify)==0)
{
printf("Password Matched...");
getch();
adminChoice();
}
else
{
printf("Wrong Password...");
getch();
}
gotoxy(21,15);
}
//Admin Menu Display
void adminMenu()
{
frame();
int row=5, col=35;
gotoxy(col,row);
textcolor(11);
cprintf("ADMIN MENU");
gotoxy(col-1,row+1);
textcolor(3);
cprintf("============");
row+=2, col=25;
gotoxy(col,row);
textcolor(9);
cprintf("0. Back to Main Menu");
row+=2, col=25;
gotoxy(col,row);
textcolor(10);
cprintf("1. Register New Flight");
row+=2, col=25;
gotoxy(col,row);
textcolor(12);
cprintf("2. Show Registered Flights");
row+=2, col=25;
gotoxy(col,row);
textcolor(13);
cprintf("3. Search Flight");
row+=2, col=25;
gotoxy(col,row);
textcolor(14);
row+=2, col=28;
gotoxy(col,row);
textcolor(15);
cprintf("Enter your choice: ");
getch();
textcolor(7);
}
void adminChoice()
{
int ch;
do
{
clrscr();
adminMenu();
scanf("%d",&ch);
clrscr();
switch(ch)
{
case 1: getData();
break;
case 2: listData();
break;
case 3: searchFlight();
break;
}
getch();
}while(ch);
}
void guestMenu()
{
frame();
int row=5, col=35;
gotoxy(col,row);
textcolor(14);
cprintf("GUEST MENU");
gotoxy(col-1,row+1);
textcolor(4);
cprintf("============");
row+=2, col=25;
gotoxy(col,row);
textcolor(13);
cprintf("0. Back to Main Menu");
row+=2, col=25;
gotoxy(col,row);
textcolor(12);
cprintf("1. Book Ticket");
row+=2, col=25;
gotoxy(col,row);
textcolor(11);
cprintf("2. View Flights");
row+=2, col=25;
gotoxy(col,row);
textcolor(10);
cprintf("3. Show Seats Layout");
row+=2, col=25;
gotoxy(col,row);
textcolor(9);
row+=2, col=28;
gotoxy(col,row);
textcolor(15);
cprintf("Enter your choice: ");
textcolor(7);
}
void guestChoice()
{
int ch;
do
{
clrscr();
guestMenu();
scanf("%d",&ch);
switch(ch)
{
case 1: getTicket(); break;
case 2: clrscr(); listData(); getch(); break;
case 3: showSeats(); getch(); break;
}
}while(ch);
}
void project()
{
int ch;
do
{
int row=5, col=35;
clrscr();
textcolor(7);
frame();
gotoxy(col-5,row);
textcolor(10);
cprintf("M A I N M E N U");
gotoxy(col-7,row+1);
textcolor(3);
cprintf("=====================");
row+=2, col=25;
gotoxy(col,row);
textcolor(11);
cprintf("0. Exit");
row+=2, col=25;
gotoxy(col,row);
textcolor(12);
cprintf("1. ADMIN MENU");
row+=2, col=25;
gotoxy(col,row);
textcolor(13);
cprintf("2. GUEST MENU");
row+=2, col=25;
gotoxy(col,row);
textcolor(14);
cprintf("3. ABOUT PROJECT");
row+=2, col=25;
gotoxy(col,row);
textcolor(8);
cprintf("4. ABOUT MYSELF");
row+=2, col=28;
gotoxy(col,row);
textcolor(15);
cprintf("Enter your choice: ");
textcolor(7);
scanf("%d",&ch);
switch(ch)
{
case 1: Login(); break;
case 2: guestChoice(); break;
case 3: acknowledge(); break;
case 4: programmers(); break;
}
}while(ch);
textcolor(7);
}
void main()
{
clrscr();
project();
getch();
}
No comments
Post your comments