Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment purpose: programmer defined functions, call by reference and call by value, simple i/o in C++, simple loop. data types string, int, and bool, class

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Assignment purpose: programmer defined functions, call by reference and call by value, simple i/o in C++, simple loop. data types string, int, and bool, class declaration with public member variables You will write a program that will play a number guessing game. The game will have 3 levels: (1) Level 1- 4 guesses, numbers 1 through 15 (2) Level 2 - 6 guesses, numbers 1 through 50 (3) Level 3 - 8 guesses, numbers 1 through 150 The number to guess will be generated with a value between 1 and an upper value depending on the level selected Get one guess at a time and provide feedback to the user, see the sample output file . Interact with the user by getting the first name Ask the user if they want to play before getting started, see the sample output file Assume the user will enter an integer for each guess (assume correct data type input) . . If the user enters a negative number, it will be too low If the user enters a number out of the range, it will be either too high or too low You do not need to force the user to enter a number in the correct range, but you will provide feedback to help the user enter a number in the correct range, see the sample output file Display the solution number at the end of each round of the game . The user should be able to continue to play another round by entering (y or Y) and end by entering (n or N) You do not need to enforce y or n, you can use Y ory to continue or you can use n or N to stop The grader will only test will values y(Y) and n(N) Use the class below to store the data for each round of numberGuess(class may not be modified) class numberGuess public: int level = 0;//game level 1, 2, or 3 int upperValue =0;//15, 50, or 150 int numGuesses = 0;//4, 6, or 8 int currentGuess = 0; //current guess input by the user int solution = 0; //pseudo random generated number int small = 0; //lowest value for feedback int large = 0;//highest value for feedback bool above = false; //current guess above the solution bool below = false; //current guess below the solution //BE SURE TO ADD COMMENTS TO THE FUNCTION PROTOTYPES AND THE FUNCTION DEFINITIONS //ADD the full comments to the function prototypes (pre and post conditions, and descriptions) //ADD brief descriptions to the function definitions Use functions to break up the program (functions may not be modified) void SetUpperRange (numberGuess& currentGame); //Description: sets the upper value of the current game based on the level void SetNumGuesses (numberGuess& currentGame); //Description: sets the maximum number of guesses for the current round based on the level void PlayOneRound (const string& name, numberGuess& currentGame); //Description: Play one round of the number guess game void GuessInput (numberGuess& currentGame) ; //Description: Displays the range, prompts, and gets the next guess from the userbool ProcessGuess (numberGuess& currentGame ) ; //Description: returns true if the guess matches the solution //returns false if they do not match //lets the user know if the guess was too high or too low void GenerateSolution (numberGuess& currentGame ) ; //Description: Generates the solution number in the correct range Additional instructions: Use function prototypes above the main function Function definitions should be placed below the main function Be sure to comment your code Include a program header with the following information: Name, due date, course, assignment number, professor name, and a brief description of the assignment - Read all comments in the sample code provided before getting started Read the problem and determine what to do Write the algorithm (you DO NOT need to submit the algorithm) Implement one component at a time in your code and do not move onto the next component until you are sure it is correct.Program 6, number game sample output: Enter your first name: Tami Hi Tami, do you want to play the guessing game? (y (Y) or n (N) ) : y what level (Enter 1, 2, or 3) ? (1) Level 1 4 guesses, numbers 1 through 15 (2) Level 2 - 6 guesses, numbers 1 through 50 (3) Level 3 - 8 guesses, numbers 1 through 150: 1 This is guess number (1 of 4) Enter a guess between 1 and 15 : 8 Your guess was too low. This is guess number (2 of 4) Enter a guess between 8 and 15 : 10 Your guess was too high. This is guess number (3 of 4) Enter a guess between 8 and 10 : 9 You won that round, Tami! THE SOLUTION WAS 9 Do you want to play another round? (y (Y) or n (N) ) : y what level (Enter 1, 2, or 3) ? (1) Level 1 - guesses, numbers 1 through 15 (2) Level 2 - 6 guesses, numbers through 50 (3) Level 3 - 8 guesses, numbers 1 through 150: 2 This is guess number (1 of 6) Enter a guess between 1 and 50 : 25 Your guess was too low. This is guess number (2 of 6) Enter a guess between 25 and 50 : 38 Your guess was too low. This is guess number (3 of 6) Enter a guess between 38 and 50 : 45 Your guess was too high.This is guess number (4 of 6) Enter a guess between 38 and 45 : 40 Your guess was too low. This is guess number (5 of 6) Enter a guess between 40 and 45 : 42 Your guess was too low. This is guess number (6 of 6) Enter a guess between 42 and 45 : 44 You won that round, Tami! THE SOLUTION WAS 44 Do you want to play another round? (y (Y) or n (N) ) : y what level (Enter 1, 2, or 3)? (1) Level 1 4 guesses, numbers 1 through 15 (2) Level 2 6 guesses, numbers 1 through 50 (3) Level 3 8 guesses, numbers 1 through 150: 3 This is guess number (1 of 8) Enter a guess between 1 and 150 : 75 Your guess was too low. This is guess number (2 of 8) Enter a guess between 75 and 150 : 85 Your guess was too high. This is guess number (3 of 8) Enter a guess between 75 and 85 : 80 Your guess was too low. This is guess number (4 of 8) Enter a guess between 80 and 85 : 82 Your guess was too low. This is guess number (5 of 8) Enter a guess between 82 and 85 : 83 Your guess was too low.This is guess number (6 of 8) Enter a guess between 83 and 85 : 84 You won that round, Tami ! THE SOLUTION WAS 84 Do you want to play another round? (y (Y) or n (N) ) :; what level (Enter 1, 2, or 3) ? (1) Level 1 4 guesses, numbers 1 through 15 (2) Level 2 - 6 guesses, numbers 1 through 50 (3) Level 3 - 8 guesses, numbers : through 150: 1 This is guess number (1 of 4) Enter a guess between 1 and 15 : 6 Your guess was too high. This is guess number (2 of 4) Enter a guess between 1 and 6 : 1 Your guess was too low. This is guess number (3 of 4) Enter a guess between 1 and 6 : 2 Your guess was too low. This is guess number (4 of 4) Enter a guess between 2 and 6 : 3 Your guess was too low. THE SOLUTION WAS 4 Do you want to play another round? (y (Y) or n (N) )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

describe how firms manage the competitive bidding process

Answered: 1 week ago

Question

Which of the these colours is least scattered by dust ,fog, smoke?

Answered: 1 week ago

Question

What is the approximate diameter of the human eye ?

Answered: 1 week ago

Question

The front transperant part of the sclerosis known as.....?

Answered: 1 week ago

Question

What is the refractive index of the cornea....?

Answered: 1 week ago

Question

Common defects of the eye?

Answered: 1 week ago