Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Write a class named Car using class separation that implements the following UML diagram: (C++) UML Diagram for Car class Car - year : int
Write a class named Car using class separation that implements the following UML diagram:
(C++)
Car |
---|
- year : int - makeModel : string - speed : int |
+ Car(i : int, s : string) + ~Car() + getYear() const : int + getMakeModel() const : string + getSpeed() const : int + accelerate() : void + brake() : void |
Here are the implementation details:
- the parameters for the constructor should be used to initialize the year and makeModel attributes, respectively
- the constructor should initialize the speed attribute to 0
- the destructor should display a message about the car crashing; the message needs to use the year and make/model
- the accelerate method should add 5 to the speed attribute and display the message "Vroom, vroom!"
- the brake method should subtract 5 from the speed attribute and display the message "skrrrrrt" only if the car has a positive speed value; otherwise, if the speed is 0, do not subtract and instead just the display a message say the car is stopped (the message should use the car's year and make/model)
In the main file, you will be prompting the user to enter their car's year and make/model information. Use that information to create a Car object. Then, write a loop that will perform the following logic a total of ten times:
- generate a random number between 0 and 99 (inclusive)
- if the random number is less than 50, call the accelerate method on the Car object you created for the user
- otherwise, call the brake method on the Car object
- regardless of the random number, the loop should always display the current speed of the user's car
Don't forget to seed the random number generator using the system time!
Sample Session
Enter the year of your car: 1967 Enter the make and model of the car: Chevrolet Camaro Vroom, vroom! Current speed: 5 skrrrrrt Current speed: 0 The 1967 Chevrolet Camaro is stopped... Current speed: 0 Vroom, vroom! Current speed: 5 Vroom, vroom! Current speed: 10 Vroom, vroom! Current speed: 15 skrrrrrt Current speed: 10 skrrrrrt Current speed: 5 Vroom, vroom! Current speed: 10 skrrrrrt Current speed: 5 The 1967 Chevrolet Camaro has crashed!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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