Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Answer in C + + using the processfeedback complier Unlimited Attempts Allowed Available: Feb 2 , 2 0 2 4 1 2 : 0 0
Answer in C using the processfeedback complier
Unlimited Attempts Allowed
Available: Feb :am until Mar :pm
Details
Overview: This project is for testing the introduction of classes and dynamic allocation of arrays of classes. In this
assignment, you will be performing a horse racing simulation. To start with, you will write a Horse class. The Horse class
should have the following member variables:
private name: A string holding the horses name.
private rider: A string holding the rider's name.
private maxRunningDistPersecond: An int that holds the maximum distance the horse could run in one second.
private distanceTraveled: How far the horse has gone already.
private raceswon: An int that determines how much races this horse and rider have won
In addition, the class should have the following constructors and member functions:
Constructor: This constructor should accept the horse's name and rider as arguments. It should initialize each horse to a
random maxRunningDistPerSecond DistanceTraveled should be set to
Accessors and mutators: Appropriate accessor and mutator functions should be used as required by the following methods:
runASecond: A method that adds to distanceTraveled an amount from maxRunningDistPerSecond. This is the method that
moves this horse along.So if a horse has "distanceTraveled" of and the goalLength passed is then the for the horse should be halfway
towards the "goal". If it is called where the distanceTraveled is greater than the goalLength indicating it has finished this
output would be:
indicating the horse has finished the race.
Demonstrate this class in a program by first prompting the user for the number of horses in the race. Then create an array of
pointers to Horse objects, filling it up as appropriate an array of pointers, so you can use the new operator to call the
constructors of each one Then prompt the user for a distance to race. Since horses can travel in any time interval a max of
a good distance of could be appropriate to test.main.cpp the main driver program.
Horse.h: The header file for the Horse class
Horse.cpp: The file defining the Horse methods
Note: If you are using an online compiler like
wwwcppsh then you may put the contents of Horse.h at the beginning of the
program, followed by the contents of Horse.cpp followed by the contents of main.cpp This way, all code will be in one
place.
Your output should look very similar to the following:Your output should look very similar to the following:
How many horses are in the race:
Please give me the name of horse : Pharaoh
Please give me the rider of rider : Mark
Please give me the name of horse : Secretariat
Please give me the name of rider : George
Please give me the name of horse : Calamity Jane
Please give me the name of rider : Mary
Please enter the distance of the race:
The start!
Pharaoh, ridden by Mark
Secretariat, ridden by George
Calamity Jane, ridden by Mary
Are you ready for the next second:y
Pharaoh, ridden by Mark
Secretariat, ridden by George
Calamity Jane, ridden by Mary
Are you ready for the next second:y
and so on until a winner is found, which would end with some output like this:and so on until a winner is found, which would end with some output like this:
Pharaoh has won races.
Secretariat has won races.
Calamity Jane has won races.
Do you wish to continueyn:
Error conditions: You must check for any invalid entries. For example, when asking for the number of horses, do not accept
negative answer and reprompt until an appropriate result is given. Only accept race distances of or greater, again re
prompting if necessary.
Note: Make sure to follow proper programming standards. This should be a good time to review the supplement, as we are
now talking about classes and member functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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