//************************************************************** // // Class: Bus class (Labtest Thursday, 1:00) // // Authors: Art Miller amiller@mta.ca // Bob Rosebrugh rrosebrugh@mta.ca // // Description: A class for bus objects // // METHODS: // Bus a constructor // busEmpty is the busEmpty? // addPassengers add passengers // removePassengers remove passengers // displayBus display the bus // // Date: November 18, 1999 // // Course Info: CS 1711, Lab test4 1:00, Thursday, Nov 18, 1999, // // Filename: bus.h // //*************************************************************** const int MAXCAPACITY = 50; const int START = 30; class Bus { private: // passengers on the bus & capcity of the bus. int passengers; int capacity; public: // initialize passengers to 20, capacity to MAXCAPACITY Bus(); bool busEmpty(); // is the bus empty ? void addPassengers (int newpassengers); // add passengers void removePassengers(int oldpassengers); // remove passengers void displayBus (); // displays the number of passengers on the bus. }; // ******************************* // Bus class implementation // ******************************* // initialize Bus Bus::Bus() { passengers = START; capacity = MAXCAPACITY; } // return whether the bus is empty bool Bus::busEmpty() { return (passengers <= 0); } void Bus::addPassengers (int newpassengers) { passengers = passengers + newpassengers; if (passengers >= capacity) passengers = capacity; } void Bus::removePassengers(int oldpassengers) // remove passengers { passengers = passengers - oldpassengers; if (passengers <= 0) passengers = 0; } void Bus::displayBus() { if (passengers <= 0) cout << "The bus is empty!"<< endl; else if (passengers >= capacity) cout << "The bus is full !"<< endl; else cout << "Passengers = " << passengers << endl; }