Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program to simulate a horse race with a random seed for the horses. The output is shown at the bottom. Program Description

Write a C++ program to simulate a horse race with a random seed for the horses. The output is shown at the bottom.image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Program Description In this lab you will write a C++ Console App that will simulate a horse race. Required Classes and Methods The diagram below shows the minimum class structure required for this program You can re-use classes done previously Horse Random private float distanceCovered public string name Horse(string name) void Run) int GetDistanceCovered() Console Program main() The Horse Class The constructor will initialise a new Horse object by receiving the name of this new horse as a string. The constructor will also store the new horse's name into the public variable name. The private variable distancecovered will hold the total distance currently covered by the horse. This variable is private to the horse, and cannot be accessed by any other class To access the distance covered by the horse, the public method GetDistanceCovered() should be called. This method will return the rounded distance covered as an int. Hint: Use the method int round (float number) . from the # include The public method Run () will add a random number (from 0 to 1, including decimals) to the private variable distanceCovered. This will make the horse run at a random speed. Hint: To generate a random float number from 0 to 1, you can simply generate a number from 0 to 10 and divide by 10. Other Classes You may write as many classes and methods as you need, as long as all the requirements are met. Remember to follow this course naming style-guide. Simulating the Race You must instantiate at least 5 horse objects. To display the horses progress you will need a loop structure that will keep calling the Run() method from all Horse objects and redrawing the lines made of the'character The race is updated once per second. The easiest way of achieving that is by calling the method Sleep( int milliseconds) from the #include at the end of the loop structure while(nowinners) // Will break loop when a horse wins the race // Race logic here Sleep (1000); // Will stop execution for 1s (1000ms) The race is over when a horse covers the distance of 20 characters, then the loop must break. Remember to use constants for values that do not change Console Output Examples Try to match these output images as close as possible (colours optional) Horse Race - Fred Stiebler Horse Race-Fred Stiebler = Horse Race = Horse Race Shadowfax Shadowfax Epona Roach = Epona Roach Pinkie Pie Pinkie Pie Wildfire Wildfire Horse Race-Fred Stiebler = Horse Race = Roach Pinkie Pie Wildfire Press any key to continue . . . Program Description In this lab you will write a C++ Console App that will simulate a horse race. Required Classes and Methods The diagram below shows the minimum class structure required for this program You can re-use classes done previously Horse Random private float distanceCovered public string name Horse(string name) void Run) int GetDistanceCovered() Console Program main() The Horse Class The constructor will initialise a new Horse object by receiving the name of this new horse as a string. The constructor will also store the new horse's name into the public variable name. The private variable distancecovered will hold the total distance currently covered by the horse. This variable is private to the horse, and cannot be accessed by any other class To access the distance covered by the horse, the public method GetDistanceCovered() should be called. This method will return the rounded distance covered as an int. Hint: Use the method int round (float number) . from the # include The public method Run () will add a random number (from 0 to 1, including decimals) to the private variable distanceCovered. This will make the horse run at a random speed. Hint: To generate a random float number from 0 to 1, you can simply generate a number from 0 to 10 and divide by 10. Other Classes You may write as many classes and methods as you need, as long as all the requirements are met. Remember to follow this course naming style-guide. Simulating the Race You must instantiate at least 5 horse objects. To display the horses progress you will need a loop structure that will keep calling the Run() method from all Horse objects and redrawing the lines made of the'character The race is updated once per second. The easiest way of achieving that is by calling the method Sleep( int milliseconds) from the #include at the end of the loop structure while(nowinners) // Will break loop when a horse wins the race // Race logic here Sleep (1000); // Will stop execution for 1s (1000ms) The race is over when a horse covers the distance of 20 characters, then the loop must break. Remember to use constants for values that do not change Console Output Examples Try to match these output images as close as possible (colours optional) Horse Race - Fred Stiebler Horse Race-Fred Stiebler = Horse Race = Horse Race Shadowfax Shadowfax Epona Roach = Epona Roach Pinkie Pie Pinkie Pie Wildfire Wildfire Horse Race-Fred Stiebler = Horse Race = Roach Pinkie Pie Wildfire Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain the various techniques of Management Development.

Answered: 1 week ago