Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write C Program Simulate Horse Race Random Seed Horses Output Shown Bottom Q35589086

Write a C++ program to simulate a horse race with a random seedfor the horses. The output is shown at the bottom.Program Description In this lab you will write a C++ Console App that will simulate a horse race. Required Classes and Method

The public method Run () will add a random number (from 0 to 1, including decimals) to the private variable distanceCovered.

Simulating the Race You must instantiate at least 5 horse objects. To display the horses progress you will need a loop struct

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 <cmath> 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 <Windows .h> 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 . . . Show transcribed image text 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 . . .

Leave a Reply

Your email address will not be published. Required fields are marked *