In this case we will do automated testing against your program. In order to do this you will prompt (ask for input) for a random seed and use it to seed your random number generator. This will allow you to test your program against several seeds. And we will test your program with a series of these random seeds. And this will not be your entire grade, but your ability to pass these tests is a part of your grade. This is a common industry practice and one we will try to introduce you.

Respuesta :

Answer:

C++ code is given below with appropriate comments

Explanation:

#include<iostream>

#include<cstdlib>

using namespace std;

// takes in the horses int array and its size

// for each horse perform a toss

void toss(int horses[],int horse_count){

               

               for(int i=0; i<horse_count;i++){

                               // if the toss result is 1 we advance the horse

                               // if the result is zero we dont advance                  

                               bool advance= rand()%2==1;

                               if(advance)horses[i]++;

               }

}

//takes in the horses int array and its size

// returns true if there is a winner

// else returns false

bool isWinner(int horses[], int horse_count){

               

               for(int i=0; i<horse_count;i++){

                               if(horses[i]>=15){

                                               cout<<"Horse "<<i<<" wins!"<<endl;      

                                               return true;

                               }

                               

               }

               return false;

}

// takes in the horses int array and its size

// prints the horses with the track

int print(int horses[], int horse_count){

               

               

               for(int i=0;i<horse_count;i++){

                               

                               for(int track=1; track<horses[i];track++)cout<<".";

                               cout<<i;

                               for(int track=horses[i]+1;track<=15;track++)cout<<".";

                               cout<<endl;      

               }

               

               cout<<endl;

               cout<<endl;

}

int main(){

               

               unsigned int seed;

               cout<<"Please enter a random seed: ";cin>>seed;

               srand(seed);

               

               const int HORSES_COUNT=5;

               // we have taken an int array

             // the numbers are all set to 1

            // if the toss turns 1 we increment the value for that horse by 1

            // we keep on incrementing until the number is 15

               int horses[HORSES_COUNT]{1};

               

               // repeat the loop until there is a winner

               while(!isWinner(horses,HORSES_COUNT)){

                               toss(horses,HORSES_COUNT);

                               print(horses,HORSES_COUNT);

               }

               

}