Question: I have the following horse race object oriented program in C++. I need this program to be converted to either C or Python, whichever is
I have the following horse race object oriented program in C++. I need this program to be converted to either C or Python, whichever is easier to do.
#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
Get step-by-step solutions from verified subject matter experts
