You are on page 1of 6

#include<fstream>

#include<conio>
#include<stdio>
#include<string>
#include<math>
struct date
{
int dd,mm,yy;
};
int chkdate(date dt)
{
int maxdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(dt.yy%100!=0 && dt.yy%4==0 || dt.yy%400==0)
maxdays[1]=29;
if(dt.mm>=1 && dt.mm<=12)
return dt.dd>=1 && dt.dd<=maxdays[dt.mm-1];
else
return 0;
}
void date2str(date dt, char* datestr)
{
sprintf(datestr, "&04i-%02i-%02i", dt.yy, dt.mm, dt.dd);
}
void displaydate(date dt)
{
printf("%02i-%02i-%04i\n", dt.dd, dt.mm, dt.yy);
}
class atime
{
int hh,mm;
int val(int h,int m) ;
public:
void input();
void display();
};
int atime::val(int h, int m)
{
if(h<=24 && h>=0 && m>=0 && m<60)
return 1;
else
return 0;
}
void atime::input()
{
do
{
cout<<endl;
cout<<"Enter hour?"; cin>>hh;
cout<<"Enter minutes?"; cin>>mm;
if(val(hh,mm)==0)
cout<<"Invalid Entry! Please try again\n";
}
while(val(hh,mm)==0);
}
void atime::display()
{
printf("%02i:%02i", hh,mm);
}
class aircraft
{
int capacity;
char flno[6], acft[4], splace[15], dplace[15];
atime deptime;
atime arrtime;
double texpense;
int acftval();
void acftin();
public:
char* retfl()
{ return flno; }
void input();
void display();
void mod();
};
int aircraft::acftval()
{
if(strcmpi(acft,"A310")==0)
{
capacity=240; return 1;
}
else
if(strcmpi(acft,"A300")==0)
{
capacity=266; return 1;
}
else
if(strcmpi(acft,"A320")==0)
{
capacity=180; return 1;
}
else
if(strcmpi(acft,"DC10")==0)
{
capacity=380; return 1;
}
else
return 0;
}
void aircraft::acftin()
{
do
{
cout<<"Enter Aircraft Model No?[A310,A320,A300,DC10] "; cin>>acft;
if(acftval()==0)
cout<<"Invalid Entry/Aircraft not in Service. Please try again\n
";
}
while(acftval()==0);
}
void aircraft::input()
{
cout<<"Enter flight no? "; cin>>flno;
acftin();
cout<<"Enter departure city? "; gets(splace);
cout<<"Enter arrival city? "; gets(dplace);
cout<<"Enter departure time? ";
deptime.input();
cout<<"Enter arrival time? ";
arrtime.input();
cout<<"Travel Expense? ";
cin>>texpense;
}
void aircraft::display()
{ 
printf("%-07s ", flno);
cout<<acft[0]<<acft[1]<<acft[2]<<acft[3];
printf(" %5i\t %-15s %-15s ", capacity, splace, dplace);
deptime.display(); cout<<" "; arrtime.display();
cout<<" "<<texpense<<" KD"<<endl;;
}
void aircraft::mod()
{
int r;
do
{
cout<<"Which field would you like to modify?\n";
cout<<"Enter 1 - for Departure place.\n";
cout<<"Enter 2 - for Arrival place.\n";
cout<<"Enter 3 - for Departure time.\n";
cout<<"Enter 4 - for Arrival time.\n";
cout<<"Enter 5 - for Travel Expenses.\n";
cout<<"Enter 6 - cancel modification.\n";
cin>>r;
switch(r)
{
case 1: cout<<"Enter new departure city? "; gets(splace); break;
case 2: cout<<"Enter new arrival city? "; gets(dplace); break;
case 3: cout<<"Enter new departure time? "; deptime.input(); break;
case 4: cout<<"Enter new arrival time? "; arrtime.input(); break;
case 5: cout<<"Enter new travel expense? "; cin>>texpense; break;
}
}
while(r!=5);
}
void sortflights()
{
int len=sizeof(aircraft);
ifstream fin("Flightlist.dat", ios::binary);
fin.seekg(0,ios::end);
int n=fin.tellg()/len;
aircraft* arr=new aircraft[n];
fin.seekg(0);
for(int c=0; c<n; c++)
fin.read((char*)&arr[c], len);
fin.close();
for(int k=1; k<n; k++)
for(int x=0; x<n-k; x++)
if(strcmpi(arr[x].retfl(), arr[x+1].retfl())>0)
{
aircraft t=arr[x];
arr[x]=arr[x+1];
arr[x+1]=t;
}
ofstream fout("Flightlist.dat", ios::binary|ios::trunc);
for(int a=0; a<n; a++)
fout.write((char*)&arr[a], len);
fout.close();
}
void addflights()
{
ofstream f("Flightlist.dat", ios::binary|ios::app);
int r;
cout<<"Enter no. of flights to add? ";
cin>>r;
aircraft t;
for(int x=0; x<r; x++)
{
cout<<"Please Enter Data for flight "<<(x+1)<<endl;
t.input();
f.write((char*)&t,sizeof(t));
}
f.close();
sortflights();
}
void modflights()
{
char item[6];
int f=0;
ifstream fin("Flightlist.dat", ios::binary);
cout<<"Enter flight no. which you want to modify? ";
gets(item);
aircraft t;
while(fin.read((char*)&t,sizeof(t)))
{
if(strcmpi(item,t.retfl())==0)
{
t.mod();
f=1;
}
}
if(f==0)
cout<<"Flight no. not found\n";
fin.close();
}
void readflights()
{
aircraft t;
ifstream fin("Flightlist.dat", ios::binary);
cout<<"Fl no. "<<"Acft "<<"Capacity"<<" Departure Place";
cout<<" Arrival Place\t"<<"D. Time\t"<<"A. Time"<<"\t Fare\n";
while(fin.read((char*)&t,sizeof(t)))
t.display();
cout<<endl;
fin.close();
}
void deleteflights()
{
aircraft t;
char item[6];
int f=0;
cout<<"Enter flight no. to delete? ";
gets(item);
ofstream fout("temp.dat", ios::binary);
ifstream fin("Flightlist.dat", ios::binary);
while(fin.read((char*)&t,sizeof(t)))
{
if(strcmpi(item, t.retfl())==0)
f=1;
else
fout.write((char*)&t,sizeof(t));
}
fin.close();
fout.close();
remove("Flightlist.dat");
rename("temp.dat","Flightlist.dat");
if(f)
cout<<"Found and deleted\n";
else
cout<<"Not found. \n";
}
void flightlist()
{
int r;
do
{
cout<<"1. Add flights to Flightlist.\n";
cout<<"2. Modify flight in Flightlist.\n";
cout<<"3. Display flightlist.\n";
cout<<"4. Delete flight in flightlist\n";
cout<<"5. Return to previous menu\n";
cin>>r;
switch(r)
{
case 1: addflights(); break;
case 2: modflights(); break;
case 3: readflights(); break;
case 4: deleteflights(); break;
}
}
while(r!=5);
}
void mainmenu()
{
int r;
do
{
cout<<"1. Manage Flight operations\n";
cout<<"2. Make a reservation\n";
cout<<"3. Cancel a reservation\n";
cout<<"4. Print Reservation Slip\n";
cout<<"5. Print Passenger Ticket\n";
cout<<"6. Print reservation chart\n";
cout<<"7. Exit\n";
cin>>r;
switch(r)
{
case 1: flightlist(); break;
case 2: cout<<"Under construction\n"; break;
case 3: cout<<"Under construction\n"; break;
case 4: cout<<"Under construction\n"; break;
case 5: cout<<"Under construction\n"; break;
case 6: cout<<"Under construction\n"; break;
default: "Invalid Entry. Please try again with 1,2,3,4,5 or 6\n";
}
}
while(r!=7);
}
void main()
{
cout<<"**********************************************************************
\n"<<endl;
cout<<"Welcome to the airline reservation program"<<endl;
cout<<"**********************************************************************
\n"<<endl;
mainmenu();
cout<<"Thank you and have a nice day.\n";
getch();
}