Advertisement
skb50bd

Mid I, Bus

Jun 10th, 2015
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Bus{
  8. private:
  9.     static int a;
  10.     int id, capacity, available_seats;
  11.     string departure_city, arrival_city;
  12.  
  13. public:
  14.     Bus(): id(a), capacity(0), available_seats(0), departure_city("N/A"), arrival_city("N/A"){++a;}
  15.     ~Bus(){}
  16.     void readData();
  17.     void updateSeats(int n);
  18.     void showData();
  19.     string getDep();
  20.     string getArr();
  21.     int getAvail();
  22. };
  23.  
  24. int Bus::a = 101;
  25.  
  26. void showCategories();
  27. void findBus(Bus *B, int nb, string departure, string arrival, int nt);
  28.  
  29. int main(){
  30.  
  31.     int nb, i, nt;
  32.     string departure, arrival;
  33.  
  34.     cout << "Bangla-Indo Joint Transportation Venture Limited" << endl;
  35.     cout << "Phase I : Bus Registration" << endl;
  36.     cout << "Enter number of buses: ";
  37.     cin >> nb;
  38.  
  39.     Bus B[nb];
  40.  
  41.     for(i = 0; i < nb; i++){
  42.         cout << "Enter info of Bus " << i + 1 << ": ";
  43.         B[i].readData();
  44.     }
  45.  
  46.     cout << "Phase II : Tickets Sale" << endl;
  47.  
  48.     do{
  49.         cout << "Enter Dep. and Arr. City and tickets: ";
  50.  
  51.         cin >> departure >> arrival >> nt;
  52.  
  53.         findBus(&B[0], nb, departure, arrival, nt);
  54.     }
  55.     while(departure != "N/A" && arrival != "N/A" && nt != 0);
  56.  
  57.     cout << "Phase III : Final Reservation Status" << endl;
  58.  
  59.     showCategories();
  60.  
  61.     for(i = 0; i < nb; i++)
  62.         B[i].showData();
  63.  
  64.     cout << "Bye Bye. Have a safe trip!" << endl;
  65.  
  66.     return 0;
  67. }
  68.  
  69.  
  70. void showCategories(){
  71.     cout << right << setw(6) << "BUS ID" << " " << left << setw(12) << "DEPARTURE" << left << setw(12) << "ARRIVAL" << right << setw(10) << "CAPACITY" << right << setw(11) << "AVAILABLE" << endl;
  72.     return;
  73. }
  74.  
  75.  
  76. void Bus::readData(){
  77.     cin >> departure_city >> arrival_city >> capacity >> available_seats;
  78.     return;
  79. }
  80.  
  81.  
  82. void Bus::updateSeats(int n){
  83.     available_seats -= n;
  84.     cout << "RESERVATIONS CONFIRMED" << endl;
  85.     return;
  86. }
  87.  
  88.  
  89. void Bus::showData(){
  90.     cout << right << setw(6) << id << " " << left << setw(12) << departure_city << left << setw(12) << arrival_city << right << setw(10) << capacity << right << setw(11) << available_seats << endl;
  91.     return;
  92. }
  93.  
  94.  
  95. string Bus::getDep(){
  96.     return departure_city;
  97. }
  98.  
  99.  
  100. string Bus::getArr(){
  101.     return arrival_city;
  102. }
  103.  
  104.  
  105. int Bus::getAvail(){
  106.     return available_seats;
  107. }
  108.  
  109.  
  110. void findBus(Bus *B, int nb, string departure, string arrival, int nt){
  111.     int i;
  112.     for(i = 0; i < nb; i++)
  113.             if(departure == B[i].getDep() && arrival == B[i].getArr()){
  114.                 if(nt <= B[i].getAvail()){
  115.                     B[i].updateSeats(nt);
  116.                     break;
  117.                 }
  118.                 else
  119.                     cout << "NOT ENOUGH SEATS. TRY LATER!" << endl;
  120.             }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement