#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
//#include<Windows.h>
struct kush
{
char passport[6];
char name[20];
char destination[15];
int seat_num;
char email[15];
struct kush *following;
}
*begin, *stream;
struct kush *dummy;
void main()
{
void reserve(int x), cancel(), display(), savefile();
int choice;
int num=1;
begin=stream=NULL;
clrscr();
do
{ clrscr();
printf("\n\n\t\t******************************************************");
printf("\n\t\t WELCOME TO HARI'S AIRLINE SYSTEM ");
printf("\n\t\t********************************************************");
printf("\n\n\n\t\tPlease Enter Your Choice From Below [1-4]:");
printf("\n\n\t\t1.Reservation");
printf("\n\n\t\t2.Cancel");
printf("\n\n\t\t3.Display Record");
printf("\n\n\t\t4.EXIT");
printf("\n\n\t\tEnter Your Choice:");
scanf("%d",&choice); fflush(stdin);
system("cls");
switch(choice)
{
case 1:
reserve(num);
num++;
break;
case 2:
cancel();
break;
case 3:
display();
break;
case 4:
{
savefile();
break;
}
default:
printf("\n\n\tOppo! Wrong Choice");
}
getch();
}while(choice!=4);
}
//*****************************************************************
void details()
{
printf("\n\t Enter Your Passport Number:");
gets(stream->passport); fflush(stdin);
printf("\n\tEnter Your Name:");
gets(stream->name); fflush(stdin);
printf("\n\tEnter Your Email:");
gets(stream->email); fflush(stdin);
printf("\n\tEnter The Destination:");
gets(stream->destination); fflush(stdin);
}
//*******************************************************************
void details();
void reserve(int x)
{
stream=begin;
if(begin==NULL)
{
begin=stream=(struct kush*)malloc(sizeof(struct kush));
details();
stream->following=NULL;
printf("\n\t Seat Booking Successful!");
printf("\n\t Your Seat Number is:Seat A-%d",x);
stream->seat_num=x;
return;
}
else if(x>15)
{
printf("\n\t\tSorry! All Seats Are Reserved\n\t\t\tTry To Next Time ");
return;
}
else
{
while(stream->following)
stream=stream->following;
stream->following=(struct kush*)malloc(sizeof(struct kush));
stream=stream->following;
details();
stream->following=NULL;
printf("\n\tSeat Booking Successful !");
printf("\n\tYour Seat Number is: Seat A-%d",x);
stream->seat_num=x;
return;
}
}
//**********************************************************************
void savefile()
{
FILE *fpointer=fopen("mufti records","w");
if(!fpointer)
{
printf("\nCann't open file!");
return;
//Sleep(800);
}
stream=begin;
while(stream)
{
fprintf(fpointer, "%-6s", stream->passport);
fprintf(fpointer, "%-15s", stream->name);
fprintf(fpointer, "%-15s", stream->email);
fprintf(fpointer, "%-15s", stream->destination);
fprintf(fpointer, "\n");
stream=stream->following;
}
printf("\n\n\tThanks For Visit Hari Airlines");
printf("\n\n\t Have A Nice Day");
fclose(fpointer);
}
//*********************************************************************
void display()
{
stream=begin;
while(stream)
{
printf("\n\n Passport Number:%-6s",stream->passport);
printf("\n Name:%-15s",stream->name);
printf("\n Email:%-15s",stream->email);
printf("\n Seat Number:A-%d",stream->seat_num);
printf("\n Destination:%-15s",stream->destination);
printf("\n\n++*=================================================*++");
stream=stream->following;
}
}
//************************************************************************
void cancel()
{
char passport[6];
stream=begin;
system("cls");
printf("\n\nEnter Passport Number To Delete Record ? ");
gets(passport); fflush(stdin);
if(strcmp(begin->passport,passport)==0)
{
dummy=begin;
begin=begin->following;
free(dummy);
printf("Booking Has Been Deleted");
//Sleep(800);
return;
}
while(stream->following)
{
if(strcmp(stream->following->passport,passport)==0)
{
dummy=stream->following;
stream->following=stream->following->following;
free(dummy);
printf("Reservation Has Been Deleted");
getch();
//Sleep(800);
return;
}
stream=stream->following;
}
printf("Oh! Please Enter Carrect Passport Number");
}