//************************************************************** // // Class: Boat class (Labtest3 Tuesday, 4:00) // // Authors: Art Miller amiller@mta.ca // Bob Rosebrugh rrosebrugh@mta.ca // // Description:A class for Boat objects // // METHODS: // Boat a constructor // loadCargo load cargo // unloadCargo unload cargo // boatFull is the boat full ? // displayCargo display the boat's cargo (tons) // // Date: November 16, 1999 // // Course Info:CS 1711, Lab test3 Tuesday, 4:00 - 5:30 // // Filename: boat.h // //*************************************************************** const int MAXCAPACITY = 400; // 400 tons maximum class Boat { private: // cargo on the Boat & capacity of the Boat. int cargo; int capacity; public: Boat(); // constructor bool boatFull(); // is the Boat full ? void loadCargo (int cargoAmount); // load additional cargo void unloadCargo (int cargoAmount); // unload some cargo void displayCargo (); // displays the tons of cargo on the Boat. }; // ******************************* // Boat class implementation // ******************************* // initialize Boat Boat::Boat() { cargo = 0; capacity = MAXCAPACITY; } // return whether the Boat is full bool Boat::boatFull() { return (cargo >= capacity); } void Boat::loadCargo (int cargoAmount) // load cargo { cargo = cargo + cargoAmount; if (cargo >= capacity) cargo = capacity; } void Boat::unloadCargo(int cargoAmount) // unload cargo { cargo = cargo - cargoAmount; if (cargo <= 0) cargo = 0; } void Boat::displayCargo() { if (cargo >= capacity) cout << "The boat is full." << endl; else if (cargo <= 0) cout << "The boat is empty." << endl; else cout << "Cargo = " << cargo << endl; }