Write a derived class of the NumberGuesser class named RandomNumberGuesser.  The derived class should override the behavior of the getCurrentGuess method.  It may also add member data and its own constructor.  It may also override the higher(), lower() and reset() methods as you see fit. To get everyone started off on the same page I have written a NumberGuesser class.  It is defined entirely in-line in the following file: NumberGuesser.h (Links to an external site.) In the current NumberGuesser class the getCurrentGuess() method returns the midpoint of the range of possible values.  In your RandomNumberGuesser class the getCurrentGuess() method should return a randomly generated number in the range of possible values. Note that repeated calls to getCurrentGuess() should always return the same value for both classes if neither the higher() or the lower() functions are called. Consider the following example: NumberGuesser *ng = new NumberGuesser(1, 10); cout << ng->getCurrentGuess(); cout << ng->getCurrentGuess(); cout << ng->getCurrentGuess(); Each invocation of getCurrentGuess should return 5. This value does not change until the higher() or lower() function is called. Now consider a RandomNumberGuesser example.  The first call to getCurrentGuess() should return a random number between 1 and 10, inclusive. Each subsequent call to getCurrentGuess() should return the same number, until higher() or lower() is called, at which point a new random number within the new range should be generated.  For example: NumberGuesser *ng = new RandomNumberGuesser(1, 10); // picks a random number between 1 and 10, let’s say it is 3, and outputs it. cout << ng->getCurrentGuess(); // this line prints out 3 again, because it is still the current guess cout << ng->getCurrentGuess(); // this line changes low to 4 because we now know the number is higher than 3. // high remains unchanged at 10. ng->higher(); // this line picks a random number between 4 and 10 and prints it out, // let’s say it is 9 cout << ng->getCurrentGuess(); // this line prints out 9 again, because it is still the current guess cout << ng->getCurrentGuess();

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a derived class of the NumberGuesser class named RandomNumberGuesser.  The derived class should override the behavior of the getCurrentGuess method.  It may also add member data and its own constructor.  It may also override the higher(), lower() and reset() methods as you see fit.

To get everyone started off on the same page I have written a NumberGuesser class.  It is defined entirely in-line in the following file: NumberGuesser.h (Links to an external site.)

In the current NumberGuesser class the getCurrentGuess() method returns the midpoint of the range of possible values.  In your RandomNumberGuesser class the getCurrentGuess() method should return a randomly generated number in the range of possible values.

Note that repeated calls to getCurrentGuess() should always return the same value for both classes if neither the higher() or the lower() functions are called. Consider the following example:

NumberGuesser *ng = new NumberGuesser(1, 10);
cout << ng->getCurrentGuess();
cout << ng->getCurrentGuess();
cout << ng->getCurrentGuess();

Each invocation of getCurrentGuess should return 5. This value does not change until the higher() or lower() function is called.

Now consider a RandomNumberGuesser example.  The first call to getCurrentGuess() should return a random number between 1 and 10, inclusive. Each subsequent call to getCurrentGuess() should return the same number, until higher() or lower() is called, at which point a new random number within the new range should be generated.  For example:

NumberGuesser *ng = new RandomNumberGuesser(1, 10);

// picks a random number between 1 and 10, let’s say it is 3, and outputs it.
cout << ng->getCurrentGuess();

// this line prints out 3 again, because it is still the current guess
cout << ng->getCurrentGuess();

// this line changes low to 4 because we now know the number is higher than 3.
// high remains unchanged at 10.
ng->higher();

// this line picks a random number between 4 and 10 and prints it out,
// let’s say it is 9
cout << ng->getCurrentGuess();

// this line prints out 9 again, because it is still the current guess
cout << ng->getCurrentGuess();

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY