Page

Air Reservation Ticket Booking System in C/C++

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main_menu();
void new_flight();
void search();
void list();
void ticket_booking();
typedef struct
{
char f_name[30];
char b_time[15];
char a_time[15];
char origin[30];
char dest[30];
int seat;
int f_no;
}flight;
typedef struct
{
char p_name[30];
char j_date[15];
char f_name[30];
int f_no;
int pnr;
int fare;
int seat_no;
char from[20];
char to[20];
}book;
FILE *fp,*fb;
int another;
void main()
{
clrscr();
gotoxy(25,10);
cprintf("Air Reservation Ticket Booking system");
gotoxy(35,12);
cprintf("By sourcecodernp.blogspot.com");
gotoxy(25,15);
textcolor(RED);
delay(6000);
main_menu();
getch();
}
void main_menu()
{
int ch;
clrscr();
gotoxy(30,6);
printf("Main Menu");
gotoxy(30,8);
printf("Add Flight          [1]");
gotoxy(30,10);
printf("Search Flight       [2]");
gotoxy(30,12);
printf("List of Flight      [3]");
gotoxy(30,14);
printf("Ticket Booking      [4]");
gotoxy(30,16);
printf("Exit                [5]");
gotoxy(30,18);
printf("Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
new_flight();
break;
case 2:
search();
break;
case 3:
list();
break;
case 4:
ticket_booking();
break;
case 5:
exit(1);
default:
main_menu();
break;
}
}
void new_flight()
{
flight f;
clrscr();
another='Y';
fp=fopen("flight.dat","ab");
while(another=='y'||another=='Y')
{
printf("Enter flight No:");
scanf("%d",&f.f_no);
fflush(stdin);
printf("Enter flight Name:");
gets(f.f_name);
fflush(stdin);
printf("Enter Bording Time");
gets(f.b_time);
fflush(stdin);
printf("Enter Arrival Time:");
gets(f.a_time);
fflush(stdin);
printf("Enter Origin:");
gets(f.origin);
fflush(stdin);
printf("Enter Destination:");
gets(f.dest);
fflush(stdin);
printf("\nEnter total seat:");
scanf("%d",&f.seat);
fwrite(&f,sizeof(f),1,fp);
cprintf("Data is inserted");
cprintf("You want to add another data:");
fflush(stdin);
another=getche();
}
fclose(fp);
getch();
main_menu();
}
void search()
{
int fno;
flight f1;
clrscr();
another='Y';
fp=fopen("flight.dat","rb");
if(fp==NULL)
{
printf("Database is Not Found");
}
printf("\nEnter Flight No:");
scanf("%d",&fno);
while(fread(&f1,sizeof(f1),1,fp)==1)
{
if(f1.f_no==fno)
{
printf("\n\nFlight is found");
printf("\n\n\tFlight No               :  %d",f1.f_no);
printf("\n\n\tFlight Name             :  %s",f1.f_name);
printf("\n\n\tBording Time            :  %s",f1.b_time);
printf("\n\n\tArrival Time            :  %s",f1.a_time);
printf("\n\n\tOrigin                  :  %s",f1.origin);
printf("\n\n\tDestination             :  %s",f1.dest);
printf("\n\n\tAvailable Seat          :  %d",f1.seat);
printf("\n\nYou want to search another flight(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='y'||another=='Y')
search();
else
{
fclose(fp);
exit(1);
}
}
}
printf("\n\nFlight is not available");
printf("\n\nDo you want to Search another medicine(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='Y'||another=='y')
search();
else
{
fclose(fp);
exit(1);
}
}
void list()
{
int p=3;
flight f2;
clrscr();
textcolor(YELLOW);
gotoxy(1,1);
cprintf("Flight No");
gotoxy(20,1);
cprintf("Flight Name");
gotoxy(45,1);
cprintf("Bording Time");
gotoxy(65,1);
cprintf("Arrival Time");
fp=fopen("flight.dat","rb");
if(fp==NULL)
{
printf("\n\nDatabase Not Found");
}
while(fread(&f2,sizeof(f2),1,fp)==1)
{
gotoxy(1,p);
printf("%d",f2.f_no);
gotoxy(20,p);
printf("%s",f2.f_name);
gotoxy(45,p);
printf("%s",f2.b_time);
gotoxy(65,p);
printf("%s",f2.a_time);
p+=2;
}
fclose(fp);
printf("\n\nPress any Key to go back Main Menu..........");
}
void ticket_booking()
{
book b;
clrscr();
another='Y';
fb=fopen("booking.dat","ab");
while(another=='y'||another=='Y')
{
printf("Enter flight No:");
scanf("%d",&b.f_no);
fflush(stdin);
printf("Enter flight Name:");
gets(b.f_name);
fflush(stdin);
printf("Passenger Name : ");
gets(b.p_name);
fflush(stdin);
printf("Enter Jounary Date:");
gets(b.j_date);
fflush(stdin);
printf("Enter Origin   :");
gets(b.from);
fflush(stdin);
printf("Enter Destination :");
gets(b.to);
fflush(stdin);
printf("Enter PNR No :");
scanf("%d",&b.pnr);
fflush(stdin);
printf("Enter Total amount :");
scanf("%d",&b.fare);
fflush(stdin);
printf("\nEnter Seat No:");
scanf("%d",&b.seat_no);
fwrite(&b,sizeof(b),1,fb);
cprintf("\nData is inserted");
cprintf("\nYou want to add another data:");
fflush(stdin);
another=getche();
}
fclose(fb);
getch();
main_menu();
}

No comments:

Post a Comment