Question: I have an object oriented C++ program of a horse race that I have put together and it functions well. Could someone go through and

I have an object oriented C++ program of a horse race that I have put together and it functions well. Could someone go through and make comments on it just kind of detailing what each section or statement does in the program. Thanks!

#include #include

class Horse { private: int position; public: Horse() { position=0; } void advance() { position+=rand()%2; } int getPosition() { return position; } };

class Race { private: Horse *h; int length; public: Race() { length=20; h=new Horse[5]; }

Race(int len) { length=len; h=new Horse[5]; }

void printLane(int i) { for(int track=1;track

while(true){ for(int i =0;i<5;i++){ h[i].advance(); } for(int i=0;i<5;i++){ printLane(i); } for(int x=0;x<5;x++){ if(h[x].getPosition()>=length){ std::cout<<"Horse "<

int main(){ unsigned int seed=0; std::cout<<"Please enter a random seed: "; std::cin>>seed; srand(seed);

int length; std::cout<<"Please enter track length: "; std::cin>>length;

Race race(length); race.start(); return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!