4. Write a C++ program that does the following: a. Create a C++ file with the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Here are C programs for the tasks you described Problem 4 ... View the full answer
Related Book For
Holt McDougal Larson Geometry
ISBN: 9780547315171
1st Edition
Authors: Ron Larson, Laurie Boswell, Timothy D. Kanold, Lee Stiff
Posted Date:
Students also viewed these programming questions
-
A company reports the following: Net income $602,000 Preferred dividends $34,000 Shares of common stock outstanding 80,000 Market price per share of common stock $58.22 a. Determine the company's...
-
Internal auditors at Henry Flower's Flower Shop are undertaking a comprehensive review to determine if the company has complied with privacy regulations regarding customer data. In the Control...
-
It takes the same amount of time to double all three accounts ($100, $200, $500). All three accounts take 13.863 to double. What can we determine about the starting amount and doubling time?
-
Assume that you are purchasing an investment and have decided to invest in a company in the digital phone business. You have narrowed the choice to Best Digital, Corp., and Every Zone, Inc., and have...
-
Empirical evidence suggests a project manager's authority, autonomy, and conflict-management skills are essential for delivering projects within the approved schedule and budget. Create a graphic...
-
How are GS designs serving the needs of formal education settings like schools?
-
1.6 Mark Du Plessis in Johannesburg. Mark Du Plessis lives in Johannesburg, South Africa. He can buy a euro for R16.3700 (South African rand). At the same time, Richard Nolan, living in Paris, can...
-
The comparative balance sheet of Beets Industries, Inc. at December 31, 2013 and 2012, is as follows: An examination of the income statement and the accounting records revealed the following...
-
CASE: The UniversityBookstore Student Computer Purchase ProgramThe University Bookstore is owned and operated by StateUniversity through an independent corporation with its own board ofdirectors. 2...
-
Hastings Company bases its variable overhead performance report on the actual direct labour- hours of the period. Data concerning the most recent year, which ended on December 31, are as follows:...
-
On January 1, 2019, Ivanhoe Company purchased equipment for $394000. The equipment is estimated to have a salvage value of $16000 and is being depreciated over eight years under the...
-
If Nick is unable to issue the additional bond for $ 8 0 0 , 0 0 0 what other options does he have to still complete the acquisition without loosing additonal ownership in his company?
-
Given the following information, calculate the effective monthly rent payment: lease term: 10 years; concession: first year free rent to be spread over the term of the lease; rental space: 5000...
-
Listed above is the 2022 Cash Flow Statement for BMW Group. Please perform horizontal analysis on the Cash Flow Statement and pick 5 accounts to explain what is happening
-
In preparing a company's statement of cash flows using the indirect method, the following information is available: Net income Accounts payable decreased by Accounts receivable increased by...
-
Congratulations! You've graduated and you have two excellent job offers. The first offer is in Buffalo, NY where the CPI is 1 8 0 and it has a salary of $ 6 5 , 0 0 0 a year. The second offer is in...
-
Question 8 (3 points) Drive Inc issued a $200,000 bond at 95. This means it was issued at a cash. Discount; $190,000 Discount, $210,000 Premium, $210,000 Premium; $190,000 and the company received...
-
Diamond Walker sells homemade knit scarves for $25 each at local craft shows. Her contribution margin ratio is 60%. Currently, the craft show entrance fees cost Diamond $1,500 per year. The craft...
-
Draw a dilation of the polygon with the given vertices using the given scale factor k. A(-4,-2), B(-2, 4), C(3, 6), D(6, 3); k = /2
-
Write a two-column proof. GIVEN CR= CS, QC L CR, QC L CS PROVE AQCR= AQCS S Q C P R
-
Find the measures of an interior angle and an exterior angle of the indicated regular polygon. Regular 18-gon
-
Tax laws can change each year. Knowing the new rules can help you save money. Log On Go to finance07.glencoe
-
Make a list of your most valuable possessions. Consider new and used items that may have collectible value. Also consider how much it would cost to replace your valuable possessions.
-
Hans has recently purchased a fully restored 1957 Chevy. The car cost \($35,000\), but for Hans, the price was worth it. The best price he can find for insurance is \($2,500\) per year. He is...
Study smarter with the SolutionInn App