Hi there, I'm trying to make a solution for this problem. Can someone please help me in writing this program. Following is the exact question that I found:
Write a program to investigate the probabilities of obtaining different results when rolling a pair of six-sided dice by simulating it using the C++ random number generator. This time, you will use an array to collect the statistical information. You will also use functions as follows:
* Write an int-valued function called getRepeti tions with no parameters. The function should ask the user for the number of dice rolls to simulate in the program, and ensure it is positive. The function should return this value.
* Write an int-valued function called rollDie with one intparameter. The function should use the rand () function to pick a random number between J and the given parameter. It should then return this number to the calling function. This will simulate the rolling of an n-sided die, where n is the value of the parameter.
* Write a void function called doRolling with three parameters: an array of ints to keep track of the number of times each number is rolled (where the elements hold the number of2's rolled, the number of3's rolled, and so on); an
* int to indicate the number of rolls required; an int to indicate the number of sides for the dice. The function should simulate the required number of rolls, and keep track of the number oftimes each value is rolled using the array.
* Write a void function called showsummary to display the results of the simulation in a neat table. This should include the number of times each value (2 through 12) was rolled, what percentage of the time each value was rolled, the theoretical percentage for each roll, and the theoretical number of times each value should have been rolled for the current test run. This function should have the same three parameters as doRo11ing had.
The main program should seed the random number generator and then use the functions to perform the task. The main program should declare the required variables as well: the number of repetitions, the array containing the counts, and any other necessary variables. Provide the output from at least three test runs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
//This is all I can understand as of now.
#include<iostream>
#include<ctime>
using namespace std;
int getRepetitions();
int rollDie(int);
void doRolling(int[], int, int);
void showSummary(int[], int, int);
double i; // Variables Declared
int main()
{
int uInput;
uInput = getRepetitions();
rollDie(uInput);
doRolling();
showSummary();
system("pause");
return 0;
} // End Main
int getRepetitions()
{
int userInput = 1;
while(userInput > 0)
{
cout << "How many times do you want to roll the dice? "<< endl;
cin >> userInput;
}
return userInput;
}
int rollDie(int userInput)
{
int counts[Max_number_of_rolls]={0};
srand(time(NULL));
int dice;
dice= 1+ rand()%6;
return dice;
}
void doRolling(int rollTimes[], int rollsRequired, int NumberOfSides)
{
cout << "----------------Rolls of the first and second dice--------------" << endl;
for(int i=0; i<rollDie; i++)
{
srand(time(NULL));
int dice;
dice= 1+ rand()%6;
counts[i]=dice;
cout << "Roll # " << i+1 << " first dice is: " << dice << endl;
dice= 1+ rand()%6;
counts[i]=counts[i]+dice; // First and Second Dice Adds Together
cout << "Roll # " << i+1 << " second dice is: " << dice << endl;
cout << "The sum is: " << counts[i] << endl;
}
cout<< "-------------Results/Statistics----------------" << endl;
// To Calculate the Percentage
for(i=2;i<13;i++)
{
int c =getRepetitions(counts,rollDie,i);
cout << "The total value of " << i <<" is repeated " << c << " out of " << rollDie << " times." << endl;
percentage= ((double)c/(double)rollDie)*100;
cout << "Percentage of the time the total value was rolled is: " << percentage << "%" << endl;
}
cout << endl << endl;
}
void showSummary(int[], int, int)
{
cout<< "-------------Results/Statistics----------------" << endl;
// To Calculate the Percentage
for(i=2;i<13;i++)
{
int c =getRepetitions(counts,rollDie,i);
cout << "The total value of " << i <<" is repeated " << c << " out of " << rollDie << " times." << endl;
percentage= ((double)c/(double)rollDie)*100;
cout << "Percentage of the time the total value was rolled is: " << percentage << "%" << endl;
}
cout << endl << endl;
}
© 2015 Microsoft Terms Privacy & cookies Developers English (United States)
| |