Question
The following is a specification of three classes: Class Vehicle: Attributes: Age, an integer -> The age of the vehicle Price, a float -> The
The following is a specification of three classes:
Class Vehicle:
Attributes:
Age, an integer -> The age of the vehicle
Price, a float -> The first name of the vehicle
Behaviors:
Vehicle() -> default constructor sets age=0, and price=0.0
setAge() -> Takes an integer parameter, returns nothing
setPrice() -> Takes a float parameter, returns nothing
getAge() -> Takes no parameters, returns the vehicles age
getPrice() -> Takes no parameters, returns the vehicles price
End Class Vehicle
Class Car:
Attributes:
An object of type Car has all the attributes of an
object of type Vehicle
Additionally, Cars have attributes that Vehicles do not:
RaceCarStatus, a boolean -> yes or no
Behaviors:
An object of type Car has all the behaviors of an object of
type Vehicle
Additionally, Cars have behaviors that Vehicles do not:
Car() -> default constructor sets RaceCarStatus=false
setRaceCarStatus() -> Takes an boolean parameter, returns nothing
getRaceCarStatus() -> Takes no parameters, returns the cars race car status
End Class Car
Class Truck:
Attributes:
An object of type Truck has all the attributes of an
object of type Vehicle
Additionally, Trucks have attributes that Vehicles do not:
DieselTypeStatus, a boolean -> yes or no
Behaviors:
An object of type Truck has all the behaviors of an object of
type Vehicle
Additionally, Cars have behaviors that Vehicles do not:
Truck() -> default constructor sets DieselTypeStatus=false
setDieselTypeStatus() -> Takes a boolean parameter, returns nothing
getDieselTypeStatus() -> Takes no parameters, returns the Trucks diesel type status
End Class Truck
It would be a horrible waste of valuable programming time to redefine all of the functions in Car or Truck when many of them are already defined. This assignment is to reinforce the application of inheritance.
Requirements:
1.) Draw three UML class diagrams, one for each of the classes mentioned above
2.) Draw a generalization among the three class diagrams, showing the inheritance relationship.
3.) Implement the three classes described earlier (Vehicle, Car and Truck) and write a driver function (main) in order to test them. For the testing, write the following test code in your main( ) :
Vehicle x;
cout << Initial value for x: << endl;
cout << Age = << x.getAge() << Price= << x.getPrice() << endl;
x.setAge(40);
x.setPrice(20000);
cout << Modified value for x: << endl;
cout << Age = << x.getAge() << Price= << x.getPrice() << endl;
repeat the above steps for Car y; and Truck z; . Note that additional behaviors in class Car and Truck should also be tested.
Display the results in tabular format (one is already done for you) as follows:
Value used for test, and what function(s) | Reason for Test | Expected Result | Actual Result |
setAge( 15 ) | To ensure that the age is setting the value properly, and that getAge( ) is returning | After setAge(15) is called, getAge() should return 15. | After using cout<< on the member function getAge(), 15 was printed. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started