Question: Write a class named Car that has the following member variables: yearModel an int that holds the cars year model make a string that holds

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

  • 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 constructor and other member functions:

  • Constructor the constructor should accept the cars year model and make as arquments. These values should be assigned to the objects yearModel and make member variables. The constructor should also assign 0 to the speed member variables.
  • Getter getter 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.

Demonstrate the class in a driver program that creates a Car object, then calls the accelerate functions five times. After each call to the accelerate function, get the current speed of the care 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. The program does not request any information from the user of the program. It simply displays information to the screen.

To compile two source code files together in one command simply provide both names. The -o allows you also to provide the name you want for the output filename. For example, you could use week3.out.

g++ week3.cpp Car.cpp -o outputfilename

To execute the output or executable file. Note that the filename is no longer a.out if you changed the name. Hence, to execute

./outputfilename

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 Databases Questions!