Question
c++ Write a class named Car that has the following member variables: carNum - A unique car number yearModel - An int that holds the
c++
Write a class named Car that has the following member variables:
carNum - A unique car number
yearModel - An int that holds the cars year model.
make - A string that holds the make of the car.
speed - An int that holds the cars current speed.
The class should have a single static variable:
carCount - This holds the current number of cars that have been created.
The class needs a static function to deal with the carCount variable:
getNextCar - This static function will increment the current carCount and return the next carNum to use. This will be used by the constructor.
In addition, the class should have the following constructor and other member functions.
Constructor - The constructor should accept the cars year model and make as arguments. These values should be assigned to the objects yearModel and make member variables. The constructor should also assign 0 to the speed member variables. The constructor should call getNextCar to set carNum.
Accessor - Appropriate accessor functions to get the values stored in an objects yearModel , make , and speed member variables.
accelerate - The accelerate function should add 5 to the speed member variable each time it is called.
brake - The brake function should subtract 5 from the speed member variable each time it is called.
getCarNum - This will return the value of the member variable carNum.
Demonstrate the class in a program that creates a Car object, prints the current carNum, and then calls the accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it. Then, call the brake function five times. After each call to the brake function, get the current speed of the car and display it. Next, create two more cars and demonstrate the same.
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