Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem A: Write a C++ program that simulates flipping a fair coin. Your program

ID: 641103 • Letter: P

Question

Problem A:

Write a C++ program that simulates flipping a fair coin. Your program should do the following:

1. Ask the user to input a random seed (of type int), and call srand with that input number as its argument. That is, right after the variable declarations in your program you should have the lines cout << "Input the random seed: "; cin >> seed; srand(seed);

2. Ask the user to input a difference value d, which should be an int.

3. Use the cmath function rand() to generate a random number that is either 0 or 1. A 0 corresponds to a tail, and 1 to a head, and both possibilities should be equally likely. Repeat this process 100 times, counting the number of heads.

4. Repeat Step 3 (i.e., generate another 100 random numbers) and count the number of heads in those 100 flips.

5. If the differences in the counts from Steps 3 and 4 is greater than or equal to the user input difference d, then stop. Otherwise repeat Steps 3 and 4 and check with the difference of the counts of these new samples is greater than or equal to d. If it is stop. Continue this process until the difference in the counts is greater than or equal to d, or Steps 3 and 4 have been repeated 8 times.

Here is an example run:

Input the random seed: 346

Input the difference: 8

Set 1 Set 2

1 54 56

2 46 49

3 51 52

4 45 48

5 55 41

Problem B:

Write another C++ program using the process in Problem A except make the following changes:

1. The user input difference d should be a double rather than an int.

2. Instead of generating a 0 or a 1 each time, generate a random number that is a double in the range [40.0, 100.0]. Each number in this range should be equally likely.

3. Print the averages with 2 digits to the right of the decimal point.

4. Instead of the stopping criterion in Problem A, always run 10 repetitions. However, after all 10 are completed, print out how many of them had their averages differ by more than the user input difference d.

5. The entire process (after setting the random seed) should be in a do - while continuation loop. So the program should always run the 10 repetitions mentioned in Step 3. Then the program should ask the user if they wish to repeat the process. If the user inputs a

Explanation / Answer

i have done upto here....hope it helps

#include <iostream>
#include <cstdlib>
using namespace std;
int rand_int(int heads, int tails);

int main()
{
unsigned int tosses,difference;
int heads, tails, k=1;
cout << "Input the random seed" << endl;
cin >> tosses;
cout << "Input the difference" << endl;
cin >> difference;
srand(tosses);
cout << "Enter Int Limits (A < B)" << endl;
cin >> heads >> tails;
cout << "Random Numbers" << endl;
for (int k=1; k<=10; k++)
{
cout << rand_int(heads,tails) << ' ';
}
cout << endl;
return (0);
}

int rand_int(int heads, int tails)
{
return rand()%(tails-heads+1) +heads;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote