180k views
3 votes
Define a class named Vehicle

Public member prototypes:
A void function named print with no parameters
A constructor with 2 integer parameters, each with a default value of 0 (zero)
Private members:
An integer to store the number of wheels.
An integer to store the number of doors.
After the Vehicle class definition:
Define the print function to display the number of wheels and doors – see sample output.
Define the constructor to populate the private variables with the values of the parameters.
Define a class named Car that derives from the Vehicle class (as public)
Public member prototypes:
A void function named print with no parameters
A constructor with 4 parameters: 3 integers each with a default value of 0 (zero), and 1 string with a default value of "" (empty string)
Private members:
An integer to store MPG (miles per gallon)
A string to store the model name
After the Car class definition:
Define the print function to display the model name and mpg, then call the parent (Vehicle) print function – see sample output
Define the constructor to call the parent (Vehicle) constructor, then populate the private Car variables with the values of the parameters.
Define a class named Truck that derives from the Vehicle class (as public)
Public member prototypes:
A void function named print with no parameters
A constructor with 5 parameters: 4 integers each with a default value of 0 (zero), and a string with a default value of "" (empty string)
Private members:
An integer to store MPG (miles per gallon)
An integer to store the number of tons the truck can carry
A string to store the model name
After the Truck class definition:
Define the print function to display the model name, mpg and tons, then call the parent (Vehicle) print function – see sample output
Define the constructor to call the parent (Vehicle) constructor, then populate the private Truck variables with the values of the parameters.
In the main function
Declare whatever local variables you need.
Prompt the user for details for a car (see sample output) and then declare a Car object.
Prompt the user for details for a truck (see sample output) and then declare a Truck object.
Call the print function for your car and your truck.

1 Answer

3 votes

Final answer:

The subject of this question is Computer Science, specifically object-oriented programming in the context of defining classes and inheritance.

Step-by-step explanation:

The subject of this question is Computer Science, specifically object-oriented programming in the context of defining classes and inheritance. The question asks the student to define classes named Vehicle, Car, and Truck, with specific member functions and private variables. The student is also asked to prompt the user for details and create objects of the Car and Truck classes, and call the print function for each object.

User Rachell
by
8.0k points