COMPUTER SCIENCE
PROJECT
FLIGHT MANAGEMENT
Submitted By
SUBANSHU BABBAR
Class: XII-A
SUBANSHU BABBAR
Class XII A
INTRODUCTION TO PROJECT
2. Files Generated…………………………………
3. Working Description……………………..
4. Coding…………………………………………………
5. Output…………………………………………………
6. Bibliography……………………………………….
Header Files
--------------------------
DATA FILES
Flc.dat
PROGRAM FILE
Flight.CPP
OBJECT FILE
Flight.obj
EXECUTION FILE
Flight.exe
WORKING DESCRIPTION
---------------------------------------
The Program consists of options as follows:
Enter a flight
Show Flights
Search Flights
Delete flights
Modify flight
Exit
CODING
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
#include<fstream.h>
#include<process.h>
#include<stdio.h>
class flight{ //class containing details of flights
int flno; //private members
char from[20];
char to[20];
int dtime;
int atime;
public: //public functions
int flightno(){return flno;} ;
void getdata()
{cout<<"Enter flight no. \n"; cin>>flno;
cout<<"Departure Place\n"; gets(from);
cout<<"Destination Place\n" ; gets(to);
cout<<"Departure Time\n"; cin>>dtime;
cout<<"Arrival Time\n" ; cin>>atime;
}
void showdata ()
{cout<<"\n\n\nFlight : "<<flno;
cout<<"\nDeparture Place : "<<from;
cout<<"\nDestination Place : "<<to;
cout<<"\nDeparture Time : "<<dtime;
cout<<"\nArrival Time : "<<atime;
}
int filno()
{return flno;}
void searchfile(); //function definitions
void writefile();
void readfile();
void deletefile();
void modify();
}a;
void main()
{clrscr();
int op=0;
while (op<=5)
{
clrscr(); //menu for option selection
cout<<"\t\t\t\t\\\\\\\\\ S&S Airways\\\\\\\\ \n\n";
cout<<"Select option:";
cout<<"\n\n 1. Enter a flight";
cout<<"\n 2. Show flights";
cout<<"\n 3. Search flights" ;
cout<<"\n 4. Delete flights" ;
cout<<"\n 5. Modify flight" ;
cout<<"\n 6. Exit \n";
cin>>op;
if (op==1)
{clrscr();
a.writefile(); }
if (op==2)
{clrscr();
cout<<"\nFlight available currently are:\n\n" ;
a.readfile();}
getch();
if (op==3)
{clrscr();
a.searchfile();
getch();
}
if (op==4)
{clrscr();
a.deletefile();
getch();
}
if (op==5)
{clrscr();
a.modify();}
}}
fstream f("flc.dat",ios::in) ;
fstream file("temp.dat",ios::out);
cout<<"Enter flight no to be deleted" ;
cin>>fln;
while(f.read((char*) &a, sizeof(a)))
{if (a.filno()==fln)
{a.showdata();
cout<<"Are you sure you want to delete this flight? (y/n)";cin>>ch;
if (ch=='n')
file.write((char*) &a,sizeof(a));
}
else file.write((char*) &a,sizeof(a));
}
file.close();
f.close();
remove("flc.dat");
rename("temp.dat","flc.dat");
}
void flight::modify() //function to modify flight
{ fstream f("flc.dat",ios::in|ios::out|ios::binary);
int fln;
long pos;
char fr[20],tr[20] ;
int at,dt;
cout<<"Enter flight no. of flight to be modified";cin>>fln;
while (!f.eof())
{pos=f.tellg();
f.read((char*) &a, sizeof(a));
if (a.filno()==fln)
{a.showdata();
cout<<"\n\nEnter '.' if you want to retain the old one";
cout<<"\nEnter New Departure Place"; gets(fr);
cout<<"\nEnter New Destination Place"; gets(tr);
cout<<"\n\n Enter -1 to retain old one";
cout<<"\nEnter New Departure Time"; cin>>dt;
cout<<"\nEnter New Arrival Time"; cin>>at;
if (strcmp(fr,".")!=0)
strcpy(from,fr);
if (strcmp(tr,".")!=0)
strcpy(to,tr);
if (dt!=-1 )
dtime=dt;
if (at!=-1)
atime=at;
}
f.seekg(pos);
f.write((char*) &a, sizeof(a));
}}
OUTPUT
BIBLIOGRAPHY
--------------------------------
www.stackoverflow.com
www.cplusplus.com
www.slideshare.net