A class hierarchy is composed of the following three (3) classes:

  • An abstract base class MotorVehicle,
  • a class Automobile (runs on fuel only), and
  • a class HybridAuto (runs on fuel and batteries).

The class hierarchy has an inheritance structure given by the UML class diagram below see image.

In separate file MotorVehicleHierarchy.cpp provided to you, there are:

  • headers for all classes,
  • nonmember functions printData and printToFile and
  • main function.

Please note the following:

  • MotorVehicleHierarchy.cpp contains the number of points awarded for each correctly implemented function.
  • There are NO syntax errors in file MotorVehicleHierarchy.cpp provided to you. Therefore, you must not change any of the code provided.
  • Changes to given code MotorVehicleHierarchy.cpp will be considered as errors, and marks will be deducted for doing so. In addition, any changes to given code will result in penalties as described in the last page of this exam.
  • Therefore, you must implement all member functions for all classes in the manner described in points (1) and (2) of following two pages, as well as in the comments in MotorVehicleHierarchy.cpp.

(1) Implement all classes so that execution of MotorVehicle Hierarchy.cpp outputs to the screen the following text in green (there are NO blank lines after the first line of text):

MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
Output v1: 50 20 4 500 4
Output new v1: 100 75 6 1000 4
MotorVehicle 100 75 6 1000 in construction
Automobile 100 75 6 1000 4 being copied
Output c2: 100 75 6 1000 4
MotorVehicle 200 100 8 5000 in construction
Automobile 200 100 8 5000 4 in construction
MotorVehicle 201 101 9 5001 in construction
Automobile 201 101 9 5001 5 being copied
Automobile 201 101 9 5001 5 in destruction
MotorVehicle 201 101 9 5001 in destruction
Output after ++c3 and c3++: 202 102 10 5002 6
MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
Automobile 402 252 22 7002 14 in destruction
MotorVehicle 402 252 22 7002 in destruction
Automobile 200 150 12 2000 8 in destruction
MotorVehicle 200 150 12 2000 in destruction
Output c4: 402 252 22 7002 14
MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
HybridAuto 50 20 4 500 4 2 0 0 in construction
Output hc1 with bidArray IDs: 50 20 4 500 4 6 10 20 30 40 50 60
MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
HybridAuto 50 20 4 500 4 2 0 0 in construction
Output hc2: 50 20 4 500 4 2 0 0
MotorVehicle 50 20 4 500 in construction
Automobile 50 20 4 500 4 in construction
HybridAuto 50 20 4 500 4 2 0 0 being copied
Output hc3: 50 20 4 500 4 2 0 0
Output hc2 after assignment: 50 20 4 500 4 6 10 20 30 40 50 60
Output hc2 after change with int: 50 20 4 1000 4 6 10 20 30 40 50 60
Output hc2 after change with float: 50 20 4 2300 4 6 10 20 30 40 50 60
HybridAuto 50 20 4 500 4 2 0 0 in destruction
Automobile 50 20 4 500 4 in destruction
MotorVehicle 50 20 4 500 in destruction
HybridAuto 50 20 4 2300 4 6 10 20 30 40 50 60 in destruction
Automobile 50 20 4 2300 4 in destruction
MotorVehicle 50 20 4 2300 in destruction
HybridAuto 50 20 4 500 4 6 10 20 30 40 50 60 in destruction
Automobile 50 20 4 500 4 in destruction
MotorVehicle 50 20 4 500 in destruction
Automobile 402 252 22 7002 14 in destruction
MotorVehicle 402 252 22 7002 in destruction
Automobile 202 102 10 5002 6 in destruction
MotorVehicle 202 102 10 5002 in destruction
Automobile 100 75 6 1000 4 in destruction
MotorVehicle 100 75 6 1000 in destruction
Automobile 100 75 6 1000 4 in destruction
MotorVehicle 100 75 6 1000 in destruction

(2) Implement all classes so that execution of MotorVehicleHierarchy.cpp outputs to a file named COEN244_Final.txt the following text in brown (there are NO blank lines after the first line of text):

100 75 6 1000 4
100 75 6 1000 4
202 102 10 5002 6
402 252 22 7002 14
50 20 4 500 4 6 10 20 30 40 50 60
50 20 4 500 4 2 0 0
50 20 4 500 4 2 0 0
50 20 4 500 4 6 10 20 30 40 50 60
50 20 4 1000 4 6 10 20 30 40 50 60
50 20 4 2300 4 6 10 20 30 40 50 60
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.