// This is the test program and question description for SYSC 2002 lab #2 version #1 (D1) // You are to write and submit files "GasTank.h" and "GasTank.cpp". // The following code and the sample executable should make it clear as to what methods are required and what they do. // You must, of course, create the necessary member variables (fields) for your GasTank class. // Note that the final version of the Date class (Date.h and Date.cpp) is provided on the G: drive for reference. #include "stdstuff.h" #include "GasTank.h" void realMain () { GasTank clunker(200), bug, prius(800); // Car "clunker" can go 200km on a tank of gas // Car "bug" can go the default, i.e. 400km, on a tank of gas // Car "prius" can go 800km on a tank of gas // Note that all the cars start out with empty gas tanks. try { GasTank bmw(-500); } catch (invalid_argument &e) { cout << "Invalid Argument Exception for car bmw <" << e.what() << "> occurred.\n\n"; } clunker.fill(); // fills the clunker's gas tank bug.fill(); // fills the bug's gas tank clunker.drive(100); // the clunker drives 100km bug.drive(200); // the bug drives 200km prius.drive(100); // the prius tries to drive 100km, but as it has no gas, this statement has no effect try { clunker.drive(-100); } catch (invalid_argument &e) { cout << "Invalid Argument Exception for car clunker <" << e.what() << "> occurred.\n\n"; } prius.fill(); // fills the prius' gas tank prius.drive(700); // the prius drives 700km cout << "Car clunker can drive " << clunker.kmLeft() << "km before it runs out of gas.\n"; // kmLeft should return 100 cout << "Car bug can drive " << bug.kmLeft() << "km before it runs out of gas.\n"; // kmLeft should return 200 cout << "Car prius can drive " << prius.kmLeft() << "km before it runs out of gas.\n\n"; // kmLeft should return 100 cout << "Car clunker's gas tank is "; clunker.printLevel(); // should print 50 cout << "% full.\nCar bug's gas tank is "; bug.printLevel(); // should print 50 cout << "% full.\nCar prius' gas tank is "; prius.printLevel(); // should print 12.5 cout << "% full.\n\n"; // fill all the tanks clunker.fill(); bug.fill(); prius.fill(); cout << "Car clunker can drive " << clunker.kmLeft() << "km before it runs out of gas.\n"; // kmLeft should return 200 cout << "Car bug can drive " << bug.kmLeft() << "km before it runs out of gas.\n"; // kmLeft should return 400 cout << "Car prius can drive " << prius.kmLeft() << "km before it runs out of gas.\n\n"; // kmLeft should return 800 cout << "Car clunker's gas tank is "; clunker.printLevel(); // should print 100 cout << "% full.\nCar bug's gas tank is "; bug.printLevel(); // should print 100 cout << "% full.\nCar prius' gas tank is "; prius.printLevel(); // should print 100 cout << "% full.\n\n"; } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }