Question: 4. Write a C++ program that does the following: a. Create a C++ file with the name problem4.cpp. b. Randomly generate an integer n

4. Write a C++ program that does the following: a. Create a C++ file with the name problem4.cpp. b. Randomly

4. Write a C++ program that does the following: a. Create a C++ file with the name problem4.cpp. b. Randomly generate an integer n from the range 1 to 100. c. Prompt the user to guess the integer. d. After each guess, the program gives a hint: If the guess is larger than n, then the program prints Too big. If the guess is smaller than n, then the program prints Too small. e. If the user didn't guess the integer n, then prompt the user to guess again. f. The program keeps track of the number of guesses. g. When the user's guess is correct, then print Congratulations! You took g guesses. where g is the number of guesses. Sample run of the program: Guess the integer I'm picked from the range 1 to 100: 50 Too big. 40 Too small. 45 Too big. 43 Too small. 44 Congratulations! You took 5 guesses. 5. Write a C++ program that does the following: a. Create a C++ file with the name problem5.cpp. b. Simulate repeated coin tosses with a penny. c. Simulate each penny toss by randomly generating a 0 or 1, with 0 representing heads and 1 representing tails. d. Keep a count of the numbers of O's and 1's generated per set of simulations. e. Divide the resulting counts by the total number of simulated tosses to compute the relative frequency of each possible result. f. Perform the above simulation for each of the following total number of simulated tosses: 10, 100, 1000, and 10000. Samp run of the program: Probability of heads given 10 tosses = 0.6 Probability of tails given 10 tosses = 0.4 Probability of heads given 100 tosses = 0.53 Probability of tails given 100 tosses = 0.47 Probability of heads given 1000 tosses = 0.484 Probability of tails given 1000 tosses = 0.516 Probability of heads given 10000 tosses = 0.4974 Probability of tails given 10000 tosses = 0.5026 2/3

Step by Step Solution

3.45 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here are C programs for the tasks you described Problem 4 ... View full answer

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 Programming Questions!