Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- class Bus{
- private:
- static int a;
- int id, capacity, available_seats;
- string departure_city, arrival_city;
- public:
- Bus(): id(a), capacity(0), available_seats(0), departure_city("N/A"), arrival_city("N/A"){++a;}
- ~Bus(){}
- void readData();
- void updateSeats(int n);
- void showData();
- string getDep();
- string getArr();
- int getAvail();
- };
- int Bus::a = 101;
- void showCategories();
- void findBus(Bus *B, int nb, string departure, string arrival, int nt);
- int main(){
- int nb, i, nt;
- string departure, arrival;
- cout << "Bangla-Indo Joint Transportation Venture Limited" << endl;
- cout << "Phase I : Bus Registration" << endl;
- cout << "Enter number of buses: ";
- cin >> nb;
- Bus B[nb];
- for(i = 0; i < nb; i++){
- cout << "Enter info of Bus " << i + 1 << ": ";
- B[i].readData();
- }
- cout << "Phase II : Tickets Sale" << endl;
- do{
- cout << "Enter Dep. and Arr. City and tickets: ";
- cin >> departure >> arrival >> nt;
- findBus(&B[0], nb, departure, arrival, nt);
- }
- while(departure != "N/A" && arrival != "N/A" && nt != 0);
- cout << "Phase III : Final Reservation Status" << endl;
- showCategories();
- for(i = 0; i < nb; i++)
- B[i].showData();
- cout << "Bye Bye. Have a safe trip!" << endl;
- return 0;
- }
- void showCategories(){
- cout << right << setw(6) << "BUS ID" << " " << left << setw(12) << "DEPARTURE" << left << setw(12) << "ARRIVAL" << right << setw(10) << "CAPACITY" << right << setw(11) << "AVAILABLE" << endl;
- return;
- }
- void Bus::readData(){
- cin >> departure_city >> arrival_city >> capacity >> available_seats;
- return;
- }
- void Bus::updateSeats(int n){
- available_seats -= n;
- cout << "RESERVATIONS CONFIRMED" << endl;
- return;
- }
- void Bus::showData(){
- 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;
- return;
- }
- string Bus::getDep(){
- return departure_city;
- }
- string Bus::getArr(){
- return arrival_city;
- }
- int Bus::getAvail(){
- return available_seats;
- }
- void findBus(Bus *B, int nb, string departure, string arrival, int nt){
- int i;
- for(i = 0; i < nb; i++)
- if(departure == B[i].getDep() && arrival == B[i].getArr()){
- if(nt <= B[i].getAvail()){
- B[i].updateSeats(nt);
- break;
- }
- else
- cout << "NOT ENOUGH SEATS. TRY LATER!" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement