I am coding a ticket Reservation System I was just planning to how to code it The problem which I am confronting is a little bit tricky. My Requirements are:
Now the problem I am facing is I am not getting a logic not to book a ticket for a passenger when the limit is exceeded. And shift its reservation to the next bus automatically.
Here is the code which I have done till yet.
#include<iostream>
using namespace std;
class BUS {
int SOD = 6;
int EOD = 22;
int capacity=0;
int BUS_NO;
public:
BUS(int no) :BUS_NO(no) {
if (capacity == 100) {
cout << "Capacity is Full\n";
return;
}
else {
if (capacity != 100)
capacity++;
}
}
int bus_No() { return BUS_NO; }
void routes() {
cout << "=========================================\n";
cout << "1.Saddar " << "2.Marrir Chowk\n";
cout << "3.Liaquat Bagh " << "4.Committe Chowk\n";
cout << "5.waris Chowk " << "6.Chandni Chowk\n";
cout << "7.Rehman " << "8.6th Road\n";
cout << "9.Shamsabad " << "10.Faizabad\n";
cout << "11.Pothar " << "12.Khayan e Johar\n";
cout << "11.Pothar " << "12.Khayan e Johar\n";
cout << "13.Faiz Ahmad Road " << "14.Kashmir Highway\n";
cout << "15.Chaman " << "16.Ibn e Sina\n";
cout << "=========================================\n";
}
void reserveTicket() {
if (capacity != 100) capacity++;
else cout << "Wait for Next Bus plzz! This is full.\n";
}
};
class PASSENG {
};
During writing this answer, I am considering that we have infinite number of buses available. Now we 3 function. 1.> ticket_book(int n)
=> This function will book ticket for the number of passengers we want. If number of passengers increases then automatically it will book ticket in next available bus. 2.> get_bus_capacity()
=> This function will return currently available seats in current bus. 3.> get_bus_number()
=> This function will return the current bus number.
#include<iostream>
using namespace std;
class BUS {
int SOD = 6;
int EOD = 22;
int capacity=0;
int BUS_NO = 1;
public:
void book_ticket(int n)
{
if(capacity + n <= 100)
{
capacity += n;
}
else
{
int cur_bus_seat = 100 - capacity;
int next_bus_seat = capacity + n - 100;
capacity = next_bus_seat;
BUS_NO += 1;
}
}
int get_bus_capacity()
{
return 100 - capacity;
}
int get_bus_no()
{
return BUS_NO;
}
void routes() {
cout << "=========================================\n";
cout << "1.Saddar " << "2.Marrir Chowk\n";
cout << "3.Liaquat Bagh " << "4.Committe Chowk\n";
cout << "5.waris Chowk " << "6.Chandni Chowk\n";
cout << "7.Rehman " << "8.6th Road\n";
cout << "9.Shamsabad " << "10.Faizabad\n";
cout << "11.Pothar " << "12.Khayan e Johar\n";
cout << "11.Pothar " << "12.Khayan e Johar\n";
cout << "13.Faiz Ahmad Road " << "14.Kashmir Highway\n";
cout << "15.Chaman " << "16.Ibn e Sina\n";
cout << "=========================================\n";
}
};
class PASSENG {
};
int main()
{
BUS bus;
int n;
while(1)
{
int choice;
cout<<"Enter Your Choice"<<"\n";
cout<<"Enter 1 to book ticket"<<"\n";
cout<<"Enter 2 to check number of seats"<<"\n";
cout<<"Enter 3 to check Bus No"<<"\n";
cin>>choice;
if(choice == 1)
{
cout<<"Enter the number of tickets to be booked";
cin>>n;
bus.book_ticket(n);
}
else if(choice == 2)
{
cout<<bus.get_bus_capacity()<<"\n";
}
else if(choice == 3)
{
cout<<bus.get_bus_no()<<"\n";
}
}
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.