Code a class named car that has the following member


I observed the following example question in my exploration of member variables/functions and was somewhat confused as to how to code such a C++ program. The example is pasted below can someone please provide source code and possible output per the requirements.

Code a class named Car that has the following member variables:

  • year. An int that holds the car's model year.
  • make. A string object that holds the make of the car.
  • speed. Holds the car's current speed.

The class should have the following member functions.

  • Constructor. The constructor should accept the car's year and make as arguments and assign these values to the object's year and make member variables. The constructor should initialize the speed member variable to 0.
  • Accessors. Accessor functions should be created to allow values to be retrieved from an object's year, 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.

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.

Solution Preview :

Prepared by a verified Expert
Basic Statistics: Code a class named car that has the following member
Reference No:- TGS02797369

Now Priced at $10 (50% Discount)

Recommended (97%)

Rated (4.9/5)