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 make to Toyota
model to Camry and cars speed to
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 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 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 c using the default constructor. Nothing is
supplied.
creating a Car object called c by providing value of for the year,
make to Ford, Taurus for the model and for the speed.
Then set speed of c object to followed by accelerate method called two
times. Followed by an accelerate with a value of followed by a brake.
Then accelerate c object by followed by brake method two times and
then accelerate one time.
Then print information about object c Make sure to print header that is
information for object c
Then print information about object c Make sure to print header that is
information for object c
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
