Programming Challenge #3

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

  • yearModel - an int that holds the car's year model
  • make - a string that holds the make of the car
  • speed - an int that holds the car's current speed

In addition, the class should have the following constructor and other member functions:

  • Constructor - The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's yearModel and make member variables. The constructor should also assign 0 to the speed member variables.
  • Accessor - appropriate accessor functions to get the values stored in an object's 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 program that creates a Car object, 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.

Implement the Programming Challenge #3.

  • There will be no input in this project.
  • All member functions need to be implemented as non-inline.
  • Write a function named simulate that will:
    • Create an array of 5 cars and for each car, accelerate by a random speed between 5 and 10. Break by random speed between 3 and 6.
    • Output the information for each car.
    • Random number generator must be randomized.
    • Call this function from your main function.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.