Professional Documents
Culture Documents
h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class TourBus
{ int bid;
char destination[200];
char time[50];
int max_seats;
int booked;
int fare;
public:
TourBus()
bid=0;
max_seats=50;
booked=0;
fare=0;
strcpy(time,"9:10am");
strcpy(destination,"delhi");
void input();
void show();
void display();
int getid()
return bid;
void book()
{
booked++;
char* getDestination()
return destination;
char* getTime()
return time;
int getBooked(){
return booked;
int getMax(){
return max_seats;
int getFare()
return fare;
};
class Ticket
char name[50];
TourBus bus;
public:
{
strcpy(name,cname);
bus=tb;
void display()
bus.show();
};
void TourBus::input()
cin>>bid;
gets(destination);
cin>>time;
cin>>fare;
void TourBus::display()
cout<<bid<<"\t"<<destination<<"\t"<<time<<"\t"<<max_seats<<"\t"<<booked<<"\t"<<fare
<<"\n";
void TourBus::show()
cout<<"Bus Id "<<bid<<endl;
cout<<"Desination "<<destination<<endl;
cout<<"Time "<<time<<endl;
void main()
int ch;
fstream F,G;
TourBus b;
do
clrscr();
cin>>ch;
switch(ch)
case 1:
F.open("tour.dat",ios::app | ios::binary);
b.input();
F.write((char*)&b, sizeof(b));
F.close();
getch();
clrscr();
break;
case 2:
int id,chk=0;
cin>>id;
F.open("tour.dat",ios::in | ios::binary);
if(F.fail())
else
while(F.read((char*)&b,sizeof(b)))
if(b.getid()==id)
b.show();
chk=1;
break;
if(chk==0)
F.close();
break;
case 3:
F.open("tour.dat",ios::in | ios::binary);
if(F.fail())
else
while(F.read((char*)&b,sizeof(b)))
b.display();
F.close();
getch();
clrscr();
break;
case 4:
chk=0;
cin>>id;
F.open("tour.dat",ios::in | ios::binary);
G.open("temp.dat",ios::out | ios::binary);
if(F.fail())
else
while(F.read((char*)&b,sizeof(b)))
if(b.getid()!=id)
G.write((char*)&b,sizeof(b));
else
{
b.show();
chk=1;
if(chk==0)
else
F.close();
G.close();
remove("tour.dat");
rename("temp.dat","tour.dat");
break;
case 5:
char dest[70],cname[50];
int bid;
Ticket t;
gets(dest);
if(F.fail())
else
while(F.read((char*)&b,sizeof(b)))
{
if(strcmp(b.getDestination(),dest)==0)
b.show();
chk=1;
gets(cname);
b.book();
t.generate(cname,b);
G.open("tickets.dat",ios::app | ios::binary);
G.write((char*)&t,sizeof(t));
G.close();
F.seekp(F.tellg()-sizeof(b),ios::beg);
F.write((char*)&b,sizeof(b));
cout<<"Ticket booked"<<endl;
getch();
break;
if(chk==0)
F.close();
break;
case 6:
G.open("tickets.dat",ios::in | ios::binary);
if(G.fail())
while(G.read((char*)&t,sizeof(t)))
t.display();
G.close();
getch();
}while(ch!=7);