0% found this document useful (0 votes)
61 views16 pages

Include

This document contains code for a bus ticket reservation system. It defines classes for buses and tickets. Buses have attributes like ID, destination, time, seats etc. Tickets contain the passenger name and details of the reserved bus. Functions allow adding new buses, displaying bus details, booking tickets, and displaying booked tickets from a file. The main function implements a menu to perform these operations in a loop until the user exits.

Uploaded by

cute labrador
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views16 pages

Include

This document contains code for a bus ticket reservation system. It defines classes for buses and tickets. Buses have attributes like ID, destination, time, seats etc. Tickets contain the passenger name and details of the reserved bus. Functions allow adding new buses, displaying bus details, booking tickets, and displaying booked tickets from a file. The main function implements a menu to perform these operations in a loop until the user exits.

Uploaded by

cute labrador
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

BUS TICKET

RESERVATION

SUBMITTED BY : KIRTIRAJ BISWAL


CLASS : XII – C
AISSCE ROLL NO. :

AISSC EXAMINATION 2019-20


BONAFIDE CERTIFICATE

This is to certify that KIRTIRAJ BISWAL of class XII, Sec-C of


MOTHER’S PUBLIC SCHOOL, Bhubaneswar with Roll Number
has satisfactorily completed the project in Computer science on “BUS
TICKET RESERVATION” in partial fulfillment of requirement of AISSCE as
prescribed by CBSE in year 2019-20.

This work was carried out by him under our supervision and guidance.

________________ __________________

Principal signature Examiner signature

________________

Teacher’s signature
ACKNOWLEDGEMENT

It is really a great pleasure to have this opportunity to express the feeling of

gratitude imprisoned in the deepest core of my heart.

At the onset, I convey my sincere gratitude to Mr. Santosh Kumar Baliarsingh,

Mothers public school, for giving me the opportunity to prepare the project and

also for his diligent guidance and continuous monitoring of the project.

I must also express my deepest gratitude to the principal of our school Mrs.

Poly Patnaik.

I cannot conclude this acknowledgement without thanking my family, relatives,

acquaintances and friends who offered their valuable cooperation to me at every

stage.
HEADER FILES USED

(1) fstream.h – for file handling, cin and cout.

(2) conio.h – for clrscr() and getch() functions.

(3) stdio.h – for standard I/O operations.

(4) string.h – for string handling.


CODING

#include<fstream.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,"");

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:

void generate(char cname[], TourBus tb)


{

strcpy(name,cname);

bus=tb;

void display()

cout<<"Customer Name "<<name<<endl;

cout<<"Details of Bus "<<endl;

bus.show();

};

void TourBus::input()

cout<<"Enter bus id ";

cin>>bid;

cout<<"Enter bus destination ";

gets(destination);

cout<<"Enter time of bus ";

cin>>time;

cout<<"Enter fare of the bus ";

cin>>fare;

void TourBus::display()
{

cout<<bid<<"\t"<<destination<<"\t"<<time<<"\t"<<max_s
eats<<"\t"<<booked<<"\t"<<fare<<"\n";

void TourBus::show()

cout<<"Bus Id "<<bid<<endl;

cout<<"Desination "<<destination<<endl;

cout<<"Time "<<time<<endl;

cout<<"No. of seats remaining "<<max_seats booked<<endl;

void main()

int ch;

fstream F,G;

TourBus b;

do

clrscr();

cout<<"Press 1 - Add a New Tour Bus"<<endl;

cout<<"Press 2 - Show Selected Bus"<<endl;

cout<<"Press 3 - Display All Buses"<<endl;


cout<<"Press 4 - Delete a Bus"<<endl;

cout<<"Press 5 - Book a ticket "<<endl;

cout<<"Press 6 - Display Booked Tickets "<<endl;

cout<<"Press 7 - Exit "<<endl;

cout<<"Enter your choice ";

cin>>ch;

switch(ch)

case 1:

F.open("tour.dat",ios::app | ios::binary);

b.input();

F.write((char*)&b, sizeof(b));

F.close();

cout<<"Bus added Successfully "<<endl;

getch();

clrscr();

break;

case 2:

int id,chk=0;

cout<<"Enter the bus id to be displayed ";

cin>>id;

F.open("tour.dat",ios::in | ios::binary);
if(F.fail())

cout<<"Can't open file "<<endl;

else

while(F.read((char*)&b,sizeof(b)))

if(b.getid()==id)

b.show();

chk=1;

break;

if(chk==0)

cout<<"Bus not Found"<<endl;

F.close();

break;

case 3:

F.open("tour.dat",ios::in | ios::binary);

if(F.fail())
cout<<"Can't open file "<<endl;

else

while(F.read((char*)&b,sizeof(b)))

b.display();

F.close();

cout<<"Press a key to continue ";

getch();

clrscr();

break;

case 4:

chk=0;

cout<<"Enter the bus id to be deleted ";

cin>>id;

F.open("tour.dat",ios::in | ios::binary);

G.open("temp.dat",ios::out | ios::binary);

if(F.fail())

cout<<"Can't open file "<<endl;

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)

cout<<"Bus not Found"<<endl;

else

cout<<"Bus Deleted "<<endl;

F.close();

G.close();

remove("tour.dat");

rename("temp.dat","tour.dat");

break;

case 5:
char dest[70],cname[50];

int bid;

Ticket t;

cout<<"Enter the destination ";

gets(dest);

F.open("tour.dat",ios::in | ios::out | ios::binary);

if(F.fail())

cout<<"Can't open file "<<endl;

else

while(F.read((char*)&b,sizeof(b)))

if(strcmp(b.getDestination(),dest)==0)

b.show();

chk=1;

cout<<"Enter the customer name ";

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)

cout<<"No Bus Found"<<endl;

/* if(b.getid()==id)

cout<<"booking"<<endl;

break;

} */

F.close();

break;

case 6:

cout<<"Booked Tickets "<<endl;

G.open("tickets.dat",ios::in | ios::binary);

if(G.fail())

cout<<"can't open file "<<endl;


else

while(G.read((char*)&t,sizeof(t)))

t.display();

G.close();

cout<<"Press a key to continue ";

getch();

while(ch!=7);

You might also like