C++ programming   For this assignment you will write up code for the same number guessing game you implemented in a previous assignment, in which the user picks a number, and your program tries to guess the number.  Each time that the program guesses a number the user responds by telling the program either the correct answer is higher or lower, or that the program’s guess is correct. A sample run of the program is printed below. In the example the user picks the value 72 for the first game, and then 25 for the second game. The user's input is in bold. Here is how the output might look: > Think of a number between 1 and 100 > Is the number 50? (h/l/c): h > Is the number 75? (h/l/c): l > Is the number 62? (h/l/c): h > Is the number 69? (h/l/c): h > Is the number 72? (h/l/c): c > You picked 72? Great pick. > Do you want to play again? (y/n): y > Think of a number Between 1 and 100 > Is the number 50? (h/l/c): l > Is the number 25? (h/l/c): c > You picked 25? Great pick. > Do you want to play again: (y/n): n > Goodbye. Notice that the program is guessing numbers, and the user is responding by entering 'h', 'l', or 'c' for higher, lower, or correct. The point of interest for us is not necessarily the game - which we have already implemented in a previous assignment - but rather the design of the program.  The essential part of this assignment is writing a NumberGuesser class.  This class will contain all of the logic for remembering the current state of the program’s guesses.   When a new instance of a NumberGuesser class is created the upper and lower bounds of the possible values should be passed into its constructor.  From that point on, a NumberGuesser object will always return the midpoint of the possible values when the getCurrentGuess() member function is called.  If the higher() or lower() member functions are called, the NumberGuesser object should adjust its private variables to represent the new possible range of values.   For example, if a NumberGuesser is created with the following line of code then the range will be the numbers from 1 to 100: NumberGuesser guesser(1, 100); If the getCurrentGuess() method is called it should return 50, which is the midpoint between 1 and 100.  If the higher() method is then called, the object should adjust its state accordingly so that it knows that the correct value is now between 51 and 100, inclusive, and getCurrentGuess() would now return 75, the midpoint between 51 and 100.  If the lower() method is then called, it should adjust its state to represent that the possible values are now between 51 and 74, and getCurrentGuess() should return 62, the midpoint between 51 and 74.  By following this strategy the number guesser should be able to eventually guess the proper value that the user guessed. As another example, here a different NumberGuesser is created with ran

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ programming

 

For this assignment you will write up code for the same number guessing game you implemented in a previous assignment, in which the user picks a number, and your program tries to guess the number.  Each time that the program guesses a number the user responds by telling the program either the correct answer is higher or lower, or that the program’s guess is correct.

A sample run of the program is printed below. In the example the user picks the value 72 for the first game, and then 25 for the second game. The user's input is in bold. Here is how the output might look:

> Think of a number between 1 and 100
> Is the number 50? (h/l/c): h
> Is the number 75? (h/l/c): l
> Is the number 62? (h/l/c): h
> Is the number 69? (h/l/c): h
> Is the number 72? (h/l/c): c
> You picked 72? Great pick.
> Do you want to play again? (y/n): y
> Think of a number Between 1 and 100
> Is the number 50? (h/l/c): l
> Is the number 25? (h/l/c): c
> You picked 25? Great pick.
> Do you want to play again: (y/n): n
> Goodbye.

Notice that the program is guessing numbers, and the user is responding by entering 'h', 'l', or 'c' for higher, lower, or correct.

The point of interest for us is not necessarily the game - which we have already implemented in a previous assignment - but rather the design of the program.  The essential part of this assignment is writing a NumberGuesser class.  This class will contain all of the logic for remembering the current state of the program’s guesses.  

When a new instance of a NumberGuesser class is created the upper and lower bounds of the possible values should be passed into its constructor.  From that point on, a NumberGuesser object will always return the midpoint of the possible values when the getCurrentGuess() member function is called.  If the higher() or lower() member functions are called, the NumberGuesser object should adjust its private variables to represent the new possible range of values.  

For example, if a NumberGuesser is created with the following line of code then the range will be the numbers from 1 to 100:

NumberGuesser guesser(1, 100);

If the getCurrentGuess() method is called it should return 50, which is the midpoint between 1 and 100.  If the higher() method is then called, the object should adjust its state accordingly so that it knows that the correct value is now between 51 and 100, inclusive, and getCurrentGuess() would now return 75, the midpoint between 51 and 100.  If the lower() method is then called, it should adjust its state to represent that the possible values are now between 51 and 74, and getCurrentGuess() should return 62, the midpoint between 51 and 74.  By following this strategy the number guesser should be able to eventually guess the proper value that the user guessed.

As another example, here a different NumberGuesser is created with range between 25 and 35:

NumberGuesser littleGuesser(25, 35);
littleGuesser.getCurrentGuess(); // should return 30
littleGuesser.higher();          // adjusts range to 31-35
littleGuesser.getCurrentGuess(); // should return 33
littleGuesser.reset();           // reset range back to original range between 25-35
littleGuesser.getCurrentGuess(); // should return 30

Here is the basic design of the NumberGuesser class that you should write. The private data variables have been left up to you.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Coding
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education