Question: C++ CODE Write a class named Car that has the following data members: yearModel: an int that holds the cars year model make: a string
C++ CODE
Write a class named Car that has the following data members: 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 In addition, the class should have the following functions: a constructor: The constructor accepts the cars year model and make as arguments. These values should be assigned to the objects yearModel and make data members. The constructor should also assign 0 to the data member speed. accelerate: This function adds 10 to the speed member variable each time it is called. brake: This function subtracts 5 from the speed member variable each time it is called. accessor: Appropriate accessor functions to get the values stored in an objects yearModel, make, and speed member variables. Demonstrate the class in a program that creates a car object, 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. Divide your program into Car.h, Car.cpp, and Lab5.cpp. (Do not forget to use include guards, #ifndef, #define, #endif). Sample Run: I am driving 2009 BMW. Current speed: 0 Accelerating... Current speed: 10 Accelerating... Current speed: 20 Accelerating... Current speed: 30 Accelerating... Current speed: 40 Accelerating... Current speed: 50 Braking... Current speed: 45 Braking... Current speed: 40 Braking... Current speed: 35 Braking... Current speed: 30 Braking... Current speed: 25
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
