Use the Car and RaceCar classes you created in the You Do It section of this chapter, or create them now. Make the following changes: a. Add fields to the Car class to hold a Car identification number...



Use the Car and RaceCar classes you created in the You Do It section of this chapter, or


create them now. Make the following changes:


a. Add fields to the Car class to hold a Car identification number and the number of miles


the Car has traveled.


b. Add a function to set the Car number. Add a function to increase the miles a Car has


traveled in the last hour. The function adds the current speed (in miles per hour) to the


number of miles traveled. Add a function to return the miles a Car has traveled so you


can display the value.


c. Alter the turnIgnitionOn()function to initialize miles traveled to zero. Alter the


showCar()function to display the newly added Car number and miles traveled in


addition to the other Car data.


d. Write a main()function that declares a Car and a RaceCar. Set a constant distance


for the length of a race—for example, 500 miles. Assign numbers to the cars, start them,


and while they have not traveled more than the race distance, select a random number


under 200 to use to set the speed of both cars, and then increase the number of miles


each car has traveled. (Because the Car and RaceCar have different maximum speeds,


during some hours they will travel at different speeds. Appendix E contains instructions


on producing random numbers.) After one of the cars exceeds the race distance, display


the winner. Save the file as Race.cpp.


e. Alter the main()function so that different random speeds are used for each car. Save


the file as Race2.cpp.


f. Alter the main()function so that both cars are RaceCars. Save the file as Race3.cpp.


g. Alter the main()function so it becomes a game. Start the user with $100 cash and ask


the user to bet an amount of money on which RaceCar will win the race. After the


race, if the user is correct, add the bet to the user’s cash, otherwise, subtract it. Display


the user’s total winnings. Continue to run races as long as the user places a bet greater


than 0. When the user is done, display the final cash value. Save the file as Race4.cpp.

May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here