0% found this document useful (0 votes)
5 views

Bus1

The document outlines a project report for a Bus Ticket Reservation System developed in C++. It includes features for both admin and customer functionalities, such as adding, displaying, and deleting bus information, as well as booking and managing tickets. The system utilizes various algorithms and file handling techniques to manage bus and ticket data efficiently.

Uploaded by

ssachidananda22
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)
5 views

Bus1

The document outlines a project report for a Bus Ticket Reservation System developed in C++. It includes features for both admin and customer functionalities, such as adding, displaying, and deleting bus information, as well as booking and managing tickets. The system utilizes various algorithms and file handling techniques to manage bus and ticket data efficiently.

Uploaded by

ssachidananda22
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/ 43

lOMoARcPSD|55521570

Bus Reservation System Report C+


+

Computer Science (Anna University)

Scan to open on Studocu


Studocu is not sponsored or endorsed by any college or university
Downloaded by sachidananda sahoo ([email protected])
lOMoARcPSD|55521570

PROJECT REPORT

Language – C++
Topic – BUS TICKET RESERVATION

Introduction
This project for reservation of bus ticket for various buses. Each bus has
50 seats. The project is inspired by travel booking sites such as
Makemytrip & RedBus. In this project, we have use the following
algorithms -

a) Searching
b) Deletion
lOMoARcPSD|55521570

c) File handling

The following is the layout of the program:

(The main menu)


1) Admin (the menu for admin, password protected)
Enter password: 212173314 i) Add a bus ii) Show
selected bus iii) Display all buses iv) Delete a bus
v) Modify a bus
vi) Exit

2) Customer (the menu for customers)


i) Book ticket
ii) Show ticket (the menu to search ticket)
a) Search by name
b) Search by phone no.
c) Exit

iii) Delete ticket (the menu to delete ticket)


a) Delete by name
b) Delete by phone no.
c) Exit iv) Exit

3) Exit Header Files


1. FSTREAM.H: For file handling, cin and cout

2. CONIO.H: For clrscr(), getch() and gotoxy()

3. STDIO.H: For standard I/O


lOMoARcPSD|55521570

operations 4. STRING.H: For string

handling

5. DOS.H: For delay()

FILES
DATA FILES

tourism.dat – to store details of bus,

i.e., ∙ Bus id,

∙ From & To,

∙ Departure & Arrival,

∙ No. of seats & No. of seats booked,

∙ Fare & GST.


ticket.dat – to store details of ticket, i.e.,

∙ Name,
lOMoARcPSD|55521570

∙ Phone no.,

∙ And details of selected bus.

PROGRAM FILE

BUS TICKET RESERVATION.CPP

CODE
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
#include<dos.h>
/
***********************
CLASS FOR BUS
***********************
/ class bus
{ int id;
char from[50]; char
dest[50]; char
timeA[10],timeD[10]; int
maxseats; int booked; int
fare; int ticbook; int gst;
lOMoARcPSD|55521570

public: bus() { ticbook=0;


id=0; maxseats=50;
booked=0;
fare=0;
strcpy(timeA,"");
strcpy(timeD,"");
strcpy(dest,"");
strcpy(from,"");
9

gst=0;
}
void input(); void
show(); void
display(); void
selectedbus();
int getid()
{
return id;
}
void ticketcount(int n)
{
ticbook=n;
}
void book(int n)
{

booked=booked+n; }
char* getfrom()
lOMoARcPSD|55521570

{
return from;
}
char* getdest()
{
return dest;
}
char* gettimeA()
{
return timeA;
10

}
char* gettimeD()
{
return timeD;
}
int getbooked()
{
return booked;
}
int getfare()
{
return fare;
}
int getgst()
{
return gst;
}
lOMoARcPSD|55521570

};
/**************************
CLASS FOR TICKET
**************************/ class ticket
{ char name[25];
char phone[15];
bus b;
public:
// FUNC. TO GENERATE TICKET
void generate(char cname[],bus tb,char cphone[])
{
11

strcpy(name,cname);
strcpy(phone,cphone);
b=tb;
}
// FUNC. TO DISPLAY TICKET
void display()
{
clrscr(); cout<<"\
n
***************************************************
* **********\n"; cout<<"\t\t\
t BUS TRAVEL AGENCY\n"; cout<<"
***************************************************
* **********\n"; gotoxy(8,6);
cout<<"CUSTOMER: "<<name ;
gotoxy(47,14);
lOMoARcPSD|55521570

cout<<"Contact No.:"<<phone;
b.show();

}
char* getname()
{ return name;
}
char* getphone()
{ return phone;
}
};
12

// FUNC. TO INPUT REQD. BUS DATA


void bus::input()
{
cout<<"Enter bus id:"; cin>>id;
cout<<"Enter starting point:";
gets(from); cout<<"Enter
destination:"; gets(dest);
cout<<"Enter time of departure:";
gets(timeD); cout<<"Enter time
of arrival:"; gets(timeA);
cout<<"Enter fare of bus:";
cin>>fare; cout<<"Enter GST:";
cin>>gst;
}

// FUNC. TO DISPLAY BUS DATA


lOMoARcPSD|55521570

void bus::display()
{

cout<<"\t"<<id<<"\t"<<from<<"\t"<<dest<<"\t"<<timeD<<"\
t"< <timeA<<"\t"<<maxseats<<"\t"<<booked<<"\t"<<fare<<"\
n"; }
// FUNC. TO SHOW DATA void
bus::show()
13

{
gotoxy(57,6);
cout<<"BUS ID: "<<id;
gotoxy(8,7);

cout<<"--------------------------------------------------------------";
gotoxy(8,8); cout<<"Journey: "<<from<<" - "<<dest;
gotoxy(8,10);
cout<<"Departure: "<<timeD;
gotoxy(47,10);
cout<<"Arrival: "<<timeA;
gotoxy(8,12); cout<<"Fare :
"<<fare; gotoxy(47,12);
cout<<"GST: "<<gst<<"%";
gotoxy(8,14);
cout<<"Tickets Booked: "<<ticbook;
gotoxy(47,18);
cout<<"TOTAL AMOUNT:
lOMoARcPSD|55521570

"<<((2*gst*fare*ticbook)/100)+
(fare*ticbook); gotoxy(46,17);
cout<<"--------------------";
gotoxy(45,18);
cout<<"|";
gotoxy(66,18);
cout<<"|";
gotoxy(46,19);
cout<<"--------------------";
gotoxy(8,20);
14

cout<<"--------------------------------------------------------------";
gotoxy(22,21); cout<<" THANK YOU, HAVE A HAPPY
JOURNEY "; gotoxy(8,22);

cout<<"********************************************
* *****************";
}
// FUNC. TO SHOW DATA OF THE SELECTED
BUS void bus::selectedbus()
{
cout<<"BUS ID.-"<<id<<endl
<<"From- "<<from<<" To- "<<dest<<endl
<<"Departure- "<<timeD<<"\tArrival-"<<timeA<<endl
<<"Fare:"<<fare<<endl
<<"GST:"<<gst<<"%"<<endl;
}
lOMoARcPSD|55521570

/**********************************
FUNC. FOR ADMIN
**********************************
/ void admin() { bus b; ticket t; int ch;
fstream f1,f2,f3,f4; do
{ clrscr();
cout<<"\n\t\t\t***********************\n";
15

cout<<"\t\t\t\tWELCOME"; cout<<"\n\t\t\
t***********************\n"; cout<<"\t\t\t 1.Add a new
bus"<<endl
<<"\t\t\t 2.Show selected bus"<<endl
<<"\t\t\t 3.Display all bus"<<endl
<<"\t\t\t 4.Delete a bus"<<endl
<<"\t\t\t 5.Modify a bus"<<endl
<<"\t\t\t 6.Exit"<<endl
<<"\t\t\t\n Enter your choice:";
cin>>ch;
switch(ch)
{
case 1 :
//ADD NEW BUS
f1.open("tourism.
dat",ios::app|
ios::binary);
b.input();
f1.write((char*)&b,sizeof(b));
lOMoARcPSD|55521570

f1.close(); cout<<"Bus added


successfully"<<endl;
getch();
clrscr(); break;
case 2 :
//SHOW SELECTED BUS
int bid,ck=0; cout<<"Enter
the bus id:"; cin>>bid;
f3.open("tourism.dat",ios::in|ios::binary);
if(f3.fail())
16

cout<<"Cant open file"<<endl;


else
{
while(f3.read((char*)&b,sizeof(b)))
{
if(b.getid()==bid)
{
b.selectedbus();
getch();
ck=1;

}
}
if(ck==0)
cout<<"Bus not found"<<endl;
}
f3.close(); break;
lOMoARcPSD|55521570

case 3 :
//DISPLAY ALL BUSES
f1.open("tourism.dat",ios::in|ios::binary);
if(f1.fail())
cout<<"Can't open file"<<endl;
else
{ clrscr(); cout<<"\
n
***************************************************
* **********\n";
cout<<"\t\t\t BUS TRAVEL AGENCY\n\n";
17

cout<<"\tBUS
ID.\tFROM\tDEST\tDEP\tARRV\tSEATS\tBOOKED\tFARE\
n"; cout<<"
***************************************************
* **********\n"; while(f1.read((char*)&b,sizeof(b)))
b.display();
}
f1.close();
cout<<"\nPress a key to continue";
getch();
clrscr(); break;
case 4 :
//DELETE A BUS ck=0;
cout<<"Enter the bus ID:";
cin>>bid;
lOMoARcPSD|55521570

f1.open("tourism.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
f3.open("ticket.dat",ios::in|ios::binary);
f4.open("temp2.dat",ios::out|ios::binary);
if(f1.fail())
cout<<"Can't open file"<<endl;
else
{
while(f1.read((char*)&b,sizeof(b)))
{
if(b.getid()!=bid)
18

{
f2.write((char*)&b,sizeof(b));
}
else
{
b.selectedbus();
ck=1;
}
}
if(ck==0)
cout<<"Bus not found"<<endl; else
cout<<"Bus deleted"<<endl; }
f1.close(); f2.close();
remove("tourism.dat");
rename("temp.dat","tourism.dat") ;
lOMoARcPSD|55521570

while(f1.read((char*)&t,sizeof(t)))
if(b.getid()!=bid)
{
f2.write((char*)&b,sizeof(b)); }
f3.close();
f4.close();
remove("ticket.dat");
rename("temp2.dat","ticket.dat");
cout<<"\nPress a key to continue";
getch();
19

clrscr();
break; case 5 :
//MODIFY A BUS cout<<"Enter bus
id to be updated:";
cin>>bid;

f1.open("tourism.dat",ios::binary|ios::in|
ios::out); if(f1.fail())
cout<<"Can't open file"<<endl;
else
{
while(f1.read((char*)&b,sizeof(b)))
{
if(b.getid()==bid)
{
f1.seekp(f1.tellg()-sizeof(b));
b.input();
lOMoARcPSD|55521570

f1.write((char*)&b,sizeof(b));
}
else
{ b.selectedbus();
ck=1;
}
}
if(ck==0) cout<<"\nBus
not found"; else
cout<<"\nBus updated\n";
20

}
f1.close();
break;
}
}while(ch!=6);
}
/****************************
FUNC. FOR CUSTOMER
****************************/
void customer()
{ int ch;
fstream f1,f2;
bus b; ticket
t;
do
lOMoARcPSD|55521570

{ clrscr()
;
cout<<"\n\t\t\t***********************\n"; cout<<"\t\t\
t\tWELCOME";
cout<<"\n\t\t\t***********************\n";
cout<<"\t\t\t 1.Book a ticket"<<endl <<"\t\t\t
2.Show ticket"<<endl
<<"\t\t\t 3.Delete ticket"<<endl
<<"\t\t\t 4.Exit"<<endl
<<"\t\t\t\n Enter your
choice:"; cin>>ch; switch(ch)
21

{
case 1 :
//BOOK A TICKET char
destination[50],cname[25],cphone[15]; int
ck=0,bid,n; f2.open("tourism.dat",ios::in|
ios::binary);
if(f2.fail())
cout<<"Can't open file"<<endl;
else
{ clrscr();
cout<<"\t\t\t BUS TRAVEL AGENCY";
cout<<"\n
***************************************************
* **********\n";
cout<<"\tBUS
lOMoARcPSD|55521570

ID.\tFROM\tDEST\tDEP\tARRV\tSEATS\tBOOKED\tFARE\
n"; cout<<"
***************************************************
* **********\n"; while(f2.read((char*)&b,sizeof(b)))
b.display();
}
f2.close(); getch();
cout<<"\n\nEnter BUS ID:";
cin>>bid; f1.open("tourism.dat",ios::in|ios::out|
ios::binary); if(f1.fail())
cout<<"Can't open file!"<<endl;
22

else
{
while(f1.read((char*)&b,sizeof(b))) {
if(b.getid()==bid)
{
b.selectedbus();
ck=1;
if(b.getbooked()>=50)
{
cout<<"\nALL TICKETS ARE
BOOKED"; }
else
{ cout<<"\nEnter the customer name:";
gets(cname);
cout<<"\nEnter the no. of tickets:";
cin>>n;
lOMoARcPSD|55521570

b.ticketcount(n);
cout<<"\nEnter the phone no.:";
gets(cphone); b.book(n);
t.generate(cname,b,cphone);
}
f2.open("ticket.dat",ios::app|ios::binary);
f2.write((char*)&t,sizeof(t));
f2.close(); f1.seekp(f1.tellg()-
sizeof(b),ios::beg);
f1.write((char*)&b,sizeof(b));
cout<<"\nTicket booked"<<endl;
23

cout<<"\n\t\t\t TICKET GENERATING";


delay(500);
cout<<".";
delay(500); cout<<".";
delay(500); cout<<".";
delay(500); cout<<".";
delay(500); cout<<".";
delay(500); cout<<".";
delay(500);
clrscr();
t.display(); cout<<"\nPress a key to
continue"<<endl; getch(); break;
}
}
if(ck==0)
lOMoARcPSD|55521570

cout<<"No record of bus found"<<endl; }


f1.close(); break;
case 2 :
//SHOW TICKET
int ch1;
24

do
{
clrscr();
//MENU FOR METHOD OF SEARCHING cout<<"\n\
t\t\t1.Search by name"
<<"\n\t\t\t2.Search by phone no"
<<"\n\t\t\t3.Exit"
<<"\nEnter choice:";
cin>>ch1;
switch(ch1)
{
case 1 :
//SEARCH BY NAME
cout<<"Enter name:";
gets(cname);
f2.open("ticket.dat",ios::in|ios::binary);
if(f2.fail())
cout<<"Can't open file!"<<endl;
else
{
while(f2.read((char*)&t,sizeof(t)))
if(strcmp(t.getname(),cname)==0)
lOMoARcPSD|55521570

{
cout<<"\nBooked Ticket\n\n";
t.display();
ck=1;
}
else if(ck==0)
{
25

cout<<"No record of ticket


found"; getch();
}
}
f2.close();
cout<<"\nPress a key to continue\n";
getch();
break;
case 2 :
//SEARCH BY PHONE NO.
cout<<"Enter phone no.:";
gets(cphone);
f2.open("ticket.dat",ios::in|ios::binary);
if(f2.fail())
cout<<"Can't open file!"<<endl;
else
{
while(f2.read((char*)&t,sizeof(t)))
if(strcmp(t.getphone(),cphone)==0)
{ ck=1;
lOMoARcPSD|55521570

cout<<"\nBooked Ticket\n\n";
t.display();
}
else if(ck==0)
{
cout<<"No record of ticket
found"; }
}
26

f2.close(); cout<<"\nPress a key to


continue\n";
getch();
break;

}
}while(ch1!=3); //END OF SEARCH MENU break;

case 3 : //DELETE
TICKET int ch2; do
{ clrscr();
cout<<"\t\t\t 1.Delete by name"
<<"\n\t\t\t 2.Delete by phone no."
<<"\n\t\t\t 3.Exit"
<<"\nEnter choice:";
cin>>ch2;
switch(ch2)
{
case 1 :
lOMoARcPSD|55521570

//DELETE BY NAME
ck=0;
cout<<"Enter name:";
gets(cname);
f1.open("ticket.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
if(f1.fail())
cout<<"Can't open file"<<endl;
27

else
{
while(f1.read((char*)&t,sizeof(t)))
if(strcmp(t.getname(),cname)!
=0)
{ f2.write((char*)&t,sizeof(t));
}
else
{ clrscr()
;
t.display();
ck=1;
}

}
if(ck==0) cout<<"Ticket not
found"<<endl; else cout<<"\
nTicket deleted"<<endl;
lOMoARcPSD|55521570

f1.close(); f2.close();
remove("ticket.dat");
rename("temp.dat","ticket.dat");
getch();
clrscr();
break; case 2 :
//DELETE BY PHONE NO.
28
ck=0;
cout<<"Enter Phone no.:";
gets(cphone);
f1.open("ticket.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
if(f1.fail())
cout<<"Can't open file"<<endl;
else
{
while(f1.read((char*)&t,sizeof(t)))
if(strcmp(t.getphone(),cphone)!
=0)
{ f2.write((char*)&t,sizeof(t)) ;
}
else
{ clrscr()
;
t.display();
ck=1;
}
lOMoARcPSD|55521570

}
if(ck==0)
cout<<"Ticket not found"<<endl;
else cout<<"\nTicket
deleted"<<endl; f1.close();
f2.close();
remove("ticket.dat");
rename("temp.dat","ticket.dat");
29

getch();
clrscr();
break;
}
}while(ch!=3); //END OF TICKET DELETION
MENU }
}while(ch!=4); //END OF ADMIN MENU
}

/*******************************
MAIN FUCTION
31

*******************************/
void main()
{ clrscr(); cout<<"\nPress any key to
continue...."; getch(); clrscr();
int ch;
//LOADING SCREEN
for(int s=0;s<100;s++)
lOMoARcPSD|55521570

{ clrscr();
gotoxy(35,12); cout<<"LOADING
"<<s<<"%"; delay(30);
}
do
{ clrscr();
cout<<"\n
***************************************************
* **********\n";
cout<<"\t\t\t B";
delay(100);
cout<<"U";
delay(100);
cout<<"S";
delay(100); cout<<"
T"; delay(100);
32

cout<<"R";
delay(100);
cout<<"A";
delay(100);
cout<<"V";
delay(100);
cout<<"E";
delay(100);
cout<<"L";
delay(100);
cout<<" A";
lOMoARcPSD|55521570

delay(100);
cout<<"G";
delay(100);
cout<<"E";
delay(100);
cout<<"N";
delay(100);
cout<<"C";
delay(100);
cout<<"Y";
delay(100);
cout<<"\n
***************************************************
* **********\n";
delay(1000); //FIRST
MENU cout<<"\t\t\t
1.Admin\n"
<<"\t\t\t 2.Customer\n"
33

<<"\t\t\t 3.Exit\n"
<<"\t\t\t\n Enter your choice:";
cin>>ch;
switch(ch)
{
case 1 :
//PASSWORD PROGRAM TO ACCESS ADMIN FUNC.
char pwd[20]; char
pswd[]="212173314";
lOMoARcPSD|55521570

cout<<"Enter password:";
for(int i=0;i<9;i++)
{ pwd[i]=getch();
cout<<"*";
}
pwd[i]='\0';
if(strcmp(pwd,pswd)==0)
{
//ACCESSING ADMIN FUNC.
admin();
}
else
cout<<"\nInvalid password!!!";
getch();

break;
case 2 :
//ACCESSING CUSTOMER FUNC.
customer(); break;
34

case 3 :
//EXIT MESSAGE
clrscr(); gotoxy(30,12);
cout<<"THANK YOU FOR VISITING";
delay(300);
clrscr();
delay(300);
gotoxy(30,12);
lOMoARcPSD|55521570

cout<<"THANK YOU
FOR VISITING";
delay(300);
clrscr(); gotoxy(30,12);
cout<<"THANK YOU FOR VISITING";
delay(300);
clrscr(); delay(300); gotoxy(30,12);
cout<<"THANK YOU FOR VISITING";
delay(300);
clrscr(); gotoxy(30,12);
cout<<"THANK YOU FOR VISITING";
delay(300);
clrscr(); delay(300); gotoxy(30,12);
cout<<"THANK YOU FOR VISITING";
35

delay(300); clrscr(); gotoxy(30,12);


cout<<"THANK YOU FOR VISITING";
delay(300);
clrscr(); delay(300);
gotoxy(30,12);
cout<<"THANK YOU FOR VISITING";
delay(300);
break;
}
}while(ch!=3);
}
/
****************************************
lOMoARcPSD|55521570

**** END OF PROGRAM


********************************************/

36

OUTPUT 37
lOMoARcPSD|55521570

38

1.Admin
lOMoARcPSD|55521570

39

i) Add new bus

ii) Show selected bus


lOMoARcPSD|55521570

40

iii) Display all buses

iv) Delete bus


lOMoARcPSD|55521570

41

v) Modify a bus
lOMoARcPSD|55521570

42

//END OF ADMIN MENU


2) Customer
lOMoARcPSD|55521570

43
i) Book ticket
lOMoARcPSD|55521570

44

ii) Show ticket

a) Search by name

b) Search by phone no.

Output for both is same:


lOMoARcPSD|55521570

iii) Delete ticket

a) Delete by name

b)Delete by phone no.

Output for both is same:


lOMoARcPSD|55521570

//END OF CUSTOMER MENU


46

3) EXIT

//END OF PROGRAM
lOMoARcPSD|55521570

Bibliography

∙ COMPUTER SCIENCE with C++ Sumita Arora CLASS XII

∙ www.google.com

∙ www.cbseportal.com
lOMoARcPSD|55521570

48

You might also like