// Examine this program named ALLVEHIC.CPP for an example that // uses all three of the classes. It uses the parent class vehicle // to declare objects and also uses the two child classes to declare // objects. This was done to illustrate that all three classes can // be used in a single program. // All three of the header files for the classes are included in // lines 3 through 5 so the program can use the components of the // classes. Notice that the implementations of the three classes are // not in view here and do not need to be in view. This allows the // code to be used without access to the source code for the actual // implementation of the class. However, it should be clear that the // header file definition must be available. // In this example program, only one object of each class is // declared and used but as many as desired could be declared and // used in order to accomplish the programming task at hand. #include #include "vehicle.h" #include "car.h" #include "truck.h" using namespace std; int main() { vehicle unicycle; unicycle.initialize(1, 12.5); cout << "The unicycle has " << unicycle.get_wheels() << " wheel.\n"; cout << "The unicycle's wheel loading is " << unicycle.wheel_loading() << " pounds on the single tire.\n"; cout << "The unicycle weighs " << unicycle.get_weight() << " pounds.\n\n"; car sedan; sedan.initialize(4, 3500.0, 5); cout << "The sedan carries " << sedan.passengers() << " passengers.\n"; cout << "The sedan weighs " << sedan.get_weight() << " pounds.\n"; cout << "The sedan's wheel loading is " << sedan.wheel_loading() << " pounds per tire.\n\n"; truck semi; semi.initialize(18, 12500.0); semi.init_truck(1, 33675.0); cout << "The semi weighs " << semi.get_weight() << " pounds.\n"; cout << "The semi's efficiency is " << 100.0 * semi.efficiency() << " percent.\n"; getchar(); return 0; } // Result of execution // // The unicycle has 1 wheel. // The unicycle's wheel loading is 12.5 pounds on the single tire. // The unicycle weighs 12.5 pounds. // // The sedan carries 5 passengers. // The sedan weighs 3500 pounds. // The sedan's wheel loading is 875 pounds per tire. // // The semi weighs 12500 pounds. // The semi's efficiency is 72.929072 percent.