Question: Write a class called Car that has the following member variables: yearModel : an int to hold car s year model. make : a string

Write a class called Car that has the following member variables:
yearModel : an int to hold cars year model.
make : a string to hold makes of the car (the company that makes the
car). Eg : Toyota.
model : a string to hold the model of the car. Eg Camry
speed : an int to hold cars current speed.
In addition, the class should have the following constructor and member functions
Constructor : will set cars year model to 2021, make to Toyota,
model to Camry and cars speed to 0.
Constructor : an overload of the Constructor above but this time, the
yearModel, make, model and speed will be provided to the constructor.
Accessors (Getters) : appropriate accessor methods for each of
the data members. These methods should be const methods.
Mutators (Setters) : appropriate mutator methods for each of the
data members.
accelerator : method to add 5 to the current value of the cars speed.
accelerator : an overload of the accelerator method above but this
time, the value to be added to current cars speed will be supplied.
brake : method to subtract 5 from the current value of the cars speed.
brake : an overload of the brake method above but this time, the value
to be subtracted from the current cars speed will be supplied.
print() : method to print the cars year model, the make and current
speed. Make sure to print what to print then followed by the value.
Demonstrate that your class is working by doing the following:
creating a Car object called c1 using the default constructor. Nothing is
supplied.
creating a Car object called c2 by providing value of 2020 for the year,
make to Ford, Taurus for the model and 75 for the speed.
Then set speed of c1 object to 50 followed by accelerate method called two
times. Followed by an accelerate with a value of 12 followed by a brake.
Then accelerate c2 object by 9 followed by brake method two times and
then accelerate one time.
Then print information about object c1. Make sure to print header that is
information for object c1.
Then print information about object c2. Make sure to print header that is
information for object c2.
Your Car class declaration, its implementation and the main() method can all be in
one .cpp file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!