0% found this document useful (0 votes)
15 views4 pages

Final Project

The document is a C++ program for a bus reservation system that allows administrators to manage bus information and users to book seats. It includes functionalities such as adding, deleting, and viewing buses, as well as booking seats. The program features a menu-driven interface for both administrators and users, with input validation for user choices.

Uploaded by

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

Final Project

The document is a C++ program for a bus reservation system that allows administrators to manage bus information and users to book seats. It includes functionalities such as adding, deleting, and viewing buses, as well as booking seats. The program features a menu-driven interface for both administrators and users, with input validation for user choices.

Uploaded by

64779
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <iostream>

#include <string>
using namespace std;

const int password = 1234;

struct Bus {
string busID;
string departure;
string destination;
int capacity;
int bookedSeats = 0;
};

Bus buses[10]; // Array to store buses that I store


int busCount = 0; // Track the number of buses count

void adminMenu();
void userMenu();
void addBus();
void deleteBus();
void viewBuses();
void bookSeat();

int main() {
int choice;

do {
cout << "\n\t\t*************************** WELCOME TO KHAN BUS RESERVATION
SYSTEM *********************************\n";
cout << "1. Administrator Options\n";
cout << "2. User Options\n";
cout << "3. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

if ([Link]()) {
[Link]();
[Link](1000, '\n');
cout << "Invalid input. Please enter a number.\n";
continue;
}

switch (choice) {
case 1:
adminMenu();
break;
case 2:
userMenu();
break;
case 3:
cout << "Exiting the system. Goodbye!\n";
return 0;
default:
cout << "Invalid choice. Please try again.\n";
}
} while (true);
return 0;
}

void adminMenu() {
int enteredPassword;
cout << "Enter administrator password: ";
cin >> enteredPassword;

if (enteredPassword != password) {
cout << "You have entered the incorrect password\n";
return;
}

int adminChoice;
do {
cout << "\n------------------------------------------- Administrator Menu --
-----------------------------------------\n";
cout << "1. Add New Bus\n";
cout << "2. Delete Bus\n";
cout << "3. View Buses\n";
cout << "4. Log back to main menu\n";
cout << "Enter your choice: ";
cin >> adminChoice;

if ([Link]()) {
[Link]();
[Link](1000, '\n');
cout << "Invalid input. Please enter a number.\n";
continue;
}

switch (adminChoice) {
case 1:
addBus();
break;
case 2:
deleteBus();
break;
case 3:
viewBuses();
break;
case 4:
cout << "Logging back to main menu\n";
return;
default:
cout << "Invalid input. Please try again....\n";
}
} while (true);
}

void userMenu() {
int userChoice;
do {
cout << "\n----------------------------------------------- User Menu -------
--------------------------------------------\n";
cout << "1. View Buses\n";
cout << "2. Book a Seat\n";
cout << "3. Log back to main menu\n";
cout << "Enter your choice: ";
cin >> userChoice;

if ([Link]()) {
[Link]();
[Link](1000, '\n');
cout << "Invalid input. Please enter a number.\n";
continue;
}

switch (userChoice) {
case 1:
viewBuses();
break;
case 2:
bookSeat();
break;
case 3:
cout << "Logging out..........\n";
return;
default:
cout << "Invalid input. Please try again.\n";
}
} while (true);
}

void addBus() {
if (busCount >= 10) {
cout << "Bus storage is full. Cannot add more buses.\n";
return;
}

Bus newBus;
cout << "Enter Bus ID: ";
cin >> [Link];
cout << "Enter Departure Location: ";
cin >> [Link];
cout << "Enter Destination: ";
cin >> [Link];
cout << "Enter Capacity: ";
cin >> [Link];

if ([Link] <= 0) {
cout << "Invalid capacity. Bus not added.\n";
return;
}

buses[busCount] = newBus;
busCount++;
cout << "Bus successfully added!\n";
}

void deleteBus() {
if (busCount == 0) {
cout << "No buses to delete.\n";
return;
}
string busID;
cout << "Enter the Bus ID to delete: ";
cin >> busID;

for (int i = 0; i < busCount; ++i) {


if (buses[i].busID == busID) {
for (int j = i; j < busCount - 1; ++j) {
buses[j] = buses[j + 1];
}
busCount--;
cout << "Bus with ID " << busID << " successfully deleted.\n";
return;
}
}

cout << "Bus with ID " << busID << " not found.\n";
}

void viewBuses() {
if (busCount == 0) {
cout << "No buses available.\n";
return;
}

cout << "Available Buses:\n";


for (int i = 0; i < busCount; ++i) {
cout << "Bus ID: " << buses[i].busID
<< ", Departure: " << buses[i].departure
<< ", Destination: " << buses[i].destination
<< ", Capacity: " << buses[i].capacity
<< ", Booked Seats: " << buses[i].bookedSeats << '\n';
}
}

void bookSeat() {
string busID;
cout << "Enter Bus ID to book a seat: ";
cin >> busID;

for (int i = 0; i < busCount; ++i) {


if (buses[i].busID == busID) {
if (buses[i].bookedSeats >= buses[i].capacity) {
cout << "No available seats on this bus.\n";
return;
}
buses[i].bookedSeats++;
cout << "Seat successfully booked on bus " << busID << ".\n";
return;
}
}

cout << "Bus with ID " << busID << " not found.\n";
}

You might also like