DITG 1113 COMPUTER PROGRAMMING
BUS RESERVATION SYSTEM FOR ADMINISTRATION
Semester 2 2017/18
COURSE : DMC
SECTION/YEAR : 4/1
LECTURER : PROFESOR MADYA DR SHARIFAH SAKINAH BINTI SYED
AHMAD
GROUP MEMBERS :
1. R.SRI HAARAN A/L M.RAMESH (D041710028)
2. MUHAMMAD AMIRUL AIMAN BIN ISKANDAR HALIM (D041710122)
3. MUHAMMAD ARIFF BIN ABD TALIB (D041710107)
4. RUBENESH A/L SUPRAMANIAM (D041710311)
INTRODUCTION
In this mini project we create the Bus Reservation Systems in C++ language. As we all know is
the common public transport that have been used by the students. Either to the campus or to the
classes or even to their hometown. Bus is one of the most use public transport by students that
does not have their own transport. Our mini project is to computerized traveling company to
manage data, so that all the transaction become fast and there should not be any error in transaction
like calculation mistake, bill generation, and other things. It replaces all paper work. It keeps
records off all bill also, giving successful implementation of the computerized Bus Reservation
System. Our reservation system has three modules. First module helps the customer to enquire the
availability of seats in a particular bus at particular date. Second module helps the customer to
reserve ticket. Using third module the customer can cancel a reserved ticket.
IMPLEMENTATION
Before the writing of our code began, we planned and design our system accordingly to our needs.
We listed our required functions and started planning the system flowchart. After the execution of
this, we started coding our system.
Functions:
1. Bus registration.
- This function asks the user for the information of a bus that they wish to register. It
will ask the bus number, the driver of the bus, the time of departure of the bus, the
time of arrival of the bus, where the bus is headed and lastly is where the bus is
headed from. Then, it will save the bus information onto an external output.
2. Reserve a seat on a bus.
- This function registers a passenger to a seat on a bus. It will ask the information of the
bus number, the seat number and the name of the passenger.
3. Show bus list.
- This function lists all the busses that are available.
4. Check the availability of seats on a bus.
- This function checks the availability of seats on a bus.
5. System reset.
- This function empties all saved data. After the process is done, the program will exit.
6. Exit program.
- This function exits the program. It will also save the number of busses and the
passenger details on each specific bus.
Flowchart :-
START
Load busCount
TRUE
busCount > 0 Load busDetail
FALSE
NO
Input Load seats
choice
Case 5
CONFIRMATION Switch (p)
YES
Case 6 Case 4 Case 3 Case 2 Case 1
bus[0].sho bus[s].Bus bus[s].Res bus[s].
w() Check(); ervation() install()
RESET
exit(0) Save busCount
Save seats
exit(0)
End
Function [ install() ] :
Function [ Reservation() ] :
Function [ show() ] :
Function [ BusCheck() ] :
SYSTEM CODING
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
int s = 0;
fstream busPassengerIn("passenger_details.txt");
fstream busPassengerOut("passenger_details.txt");
fstream busDetailsIn("bus_details.txt");
fstream busDetailsOut("bus_details.txt", ios::in | ios::out | ios::app);
fstream busCountIn("busCount.txt");
fstream busCountOut("busCount.txt");
struct ticketing
{
void install();
void Reservation();
void BusCheck();
void show();
void empty();
void position(int);
char busN[5], bdriver[15], arrival[7], departure[7], from[10], to[10],
seat[4][8][10];
}
bus[10];
int main()
{
system("cls");
int p;
int t = 0;
busCountIn >> s;
if (s > 0)
{
for (int i = 0; i < s; i++)
{
busDetailsIn >> bus[i].busN >> bus[i].bdriver >> bus[i].arrival >>
bus[i].departure >> bus[i].from >> bus[i].to;
}
for (int z = 0; z < s; z++)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 4; j++)
{
busPassengerIn >> bus[z].seat[i][j];
}
}
}
}
while (1)
{
cout <<
"\n\n*************************************************************\n";
cout << "*********Welcome to SAR BUS Service - Administration*********\n";
cout <<
"*************************************************************\n\n\n";
cout << "\t\t\t1. Bus Registration\n" << "\t\t\t2. Seat Reservation\n"
<< "\t\t\t3. Bus Listing\n" << "\t\t\t4. Check Seat Availablity\n" <<
"\t\t\t5. System Reset\n";
cout << "\t\t\t6. Exit Program\n" << "\t\t\tEnter your option :";
cin >> p;
if (p == 1 || p == 5|| p == 6 || s != 0)
{
t = 1;
}
while (t == 0)
{
cout << "Please register a bus first: ";
cin >> p;
if (p == 1 || p == 5 || p == 6)
{
t = 1;
}
}
switch (p)
{
case 1:
{
bus[s].install();
break;
}
case 2:
{
bus[s].Reservation();
break;
}
case 3:
{
bus[s].BusCheck();
break;
}
case 4:
{
bus[0].show();
break;
}
case 5:
{
cout << "Are you sure?(Y/N)\n";
top:
char choice;
cin >> choice;
if (choice == 'N'|| choice == 'n')
{
break;
}
else if (choice == 'y'|| choice == 'Y')
{
busPassengerIn.close();
busPassengerOut.close();
busDetailsIn.close();
busDetailsOut.close();
busCountIn.close();
busCountOut.close();
fstream busDetailsReset("bus_details.txt", ios::out |
ios::trunc);
fstream busCountReset("busCount.txt", ios::out | ios::trunc);
fstream busPassengerReset("passenger_details.txt", ios::out |
ios::trunc);
cout << "SYSTEM HAS BEEN RESET.";
}
else
{
cout << "INVALID INPUT.\n";
goto top;
}
}
case 6:
{
busCountOut << s;
for (int z = 0; z < s; z++)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 4; j++)
{
busPassengerOut << bus[z].seat[i][j] << " ";
}
}
}
exit(0);
}
default:
cout << "Invalid choice!!";
break;
}
}
return 0;
}
void ticketing::install()//Bus registration
{
cout << "Enter the bus number :\n";
cin >> bus[s].busN;
cout << "Enter the bus driver name :\n";
cin >> bus[s].bdriver;
cout << "Enter the arrival time :\n";
cin >> bus[s].arrival;
cout << "Enter the departure time :\n";
cin >> bus[s].departure;
cout << "From :\n";
cin >> bus[s].from;
cout << "To :\n";
cin >> bus[s].to;
bus[s].empty();
busDetailsOut << bus[s].busN << " " << bus[s].bdriver << " " << bus[s].arrival << "
" << bus[s].departure << " " << bus[s].from << " " << bus[s].to << endl;
s++;
}
void ticketing::Reservation()//Reserve a seat
{
int seat;
char num[5];
cout << "Bus no: ";
top:
cin >> num;
int a;
for (a = 0; a <= s; a++)
{
if (strcmp(bus[a].busN, num) == 0)
break;
}
while (a <= s)
{
cout << "\nSeat Number: ";
cin >> seat;
if (seat>32)
{
cout << "\nThere are only 32 seats available in this bus.";
}
else
{
if (strcmp(bus[a].seat[seat / 4][(seat % 4) - 1], "Empty") == 0)
{
cout << "Enter passanger's name: ";
cin >> bus[a].seat[seat / 4][(seat % 4) - 1];
break;
}
else
cout << "The seat no. is already reserved.\n";
}
}
if (a>s)
{
cout << "Enter correct bus no: ";
goto top;
}
void ticketing::show()//Show all busses
{
int n = 0;
char number[5];
cout << "Enter bus no: ";
top:
cin >> number;
for (n = 0; n <= s; n++)
{
if (strcmp(bus[n].busN, number) == 0)
break;
}
while (n <= s)
{
cout <<
"****************************************************************************************
*******************************" << endl;
cout << "Bus no: \t" << bus[n].busN
<< "\nDriver: \t" << bus[n].bdriver << "\t\tArrival time: \t"
<< bus[n].arrival << "\tDeparture time:" << bus[n].departure
<< "\nFrom: \t\t" << bus[n].from << "\t\tTo: \t\t" <<
bus[n].to << "\n";
cout <<
"****************************************************************************************
*******************************" << endl;
bus[0].position(n);
int a = 1;
for (int i = 0; i<8; i++)
{
for (int j = 0; j<4; j++)
{
a++;
if (strcmp(bus[n].seat[i][j], "Empty") != 0)
cout << "\nThe seat no " << (a - 1) << " is reserved for
" << bus[n].seat[i][j] << ".";
}
}
break;
if (n > s)
{
cout << "Enter correct bus no: ";
goto top;
}
}
void ticketing::BusCheck()//Checks the seats on a bus
{
for (int n = 0; n < s; n++)
{
cout <<
"****************************************************************************************
*******************************" << endl;
cout << "Bus no: \t" << bus[n].busN << "\nDriver: \t" << bus[n].bdriver
<< "\t\tArrival time: \t" << bus[n].arrival << "\tDeparture Time: \t"
<< bus[n].departure << "\nFrom: \t\t" << bus[n].from << "\t\tTo:
\t\t\t"
<< bus[n].to << "\n";
cout <<
"****************************************************************************************
*******************************" << endl;
cout <<
"________________________________________________________________________________________
_______________________________" << endl;;
}
}
void ticketing::empty()
{
for (int x = 0; x<8; x++)
{
for (int y = 0; y<4; y++)
{
strcpy_s(bus[s].seat[x][y], "Empty");
}
}
}
//Assigns all vacant seats "EMPTY"
void ticketing::position(int h) //Position of passenger drawing
{
int k = 0, p = 0;
for (int i = 0; i<8; i++)
{
cout << "\n";
for (int j = 0; j<4; j++)
{
k++;
if (strcmp(bus[h].seat[i][j], "Empty") == 0)
{
cout.width(5);
cout.fill(' ');
cout << k << ".";
cout.width(10);
cout.fill(' ');
cout << bus[h].seat[i][j];
p++;
}
else
{
cout.width(5);
cout.fill(' ');
cout << k << ".";
cout.width(10);
cout.fill(' ');
cout << bus[h].seat[i][j];
}
}
}
cout << "\n\nThere are " << p << " seats empty in Bus No: " << bus[h].busN;
}
RUNNING THE CODE
Screenshot 1 : When first running the program, the user is greeted with the menu screen.
Screenshot 2 : When user inputs a number other than 1,5,6 , the program will ask for an
input again. This is because there are no available busses that are registered
yet.
Screenshot 3 : When user inputs 1 to register bus, the system asks for the bus number, bus driver,
arrival time, departure time, place of departure and place of arrival.
Screenshot 4 : When user inputs 3 to check the available busses, the program will display the
available busses, which is bus 100.
Screenshot 5 : When user inputs 2 to reserve a seat for a passenger, the program will ask for the
bus number, the seat number, and the name for the passanger.
Screenshot 6 : When the user inputs 4 to check for the added passenger, the program asks for the
bus number. The program then will show the seats in a figure form. It will also
show the available seats and whom the seat is reserved for.
Screenshot 7 : Multiple passengers added.
Screenshot 8 : After exiting the program, the program will save all the data in highlighted
text documents. When the program is opened again, the saved data will be
loaded.
Screenshot 9 : When the user wants to remove all the saved data, they will input option number 5
and program will ask to reconfirm as all removed data will be lost. When, “Y” is
inputted, the program will overwrite all the data in the word documents with blank
and the program closes.
GANTT CHART
NAME WORK
R.SRIHAARAN Function reservation and main
MUHAMMAD AMIRUL AIMAN Function BusCheck and main
RUBENESH Function show
MUHAMMAD ARIFF Function install and introduction