Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I need help with this C++ assignment. In this assignment you will write a program in that can figure out a number chosen by a

I need help with this C++ assignment. In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.

A sample run of the program might look like this:

Guess a number between 1 and 100.

Is it 50? (h/l/c): h

Is it 75? (h/l/c): h

Is it 87? (h/l/c): l

Is it 81? (h/l/c): c

Great! Do you want to play again? (y/n): y

Guess a number between 1 and 100.

Is it 50? (h/l/c): l

Is it 25? (h/l/c): h

Is it 37? (h/l/c): c

Great! Do you want to play again? (y/n): n

Notice that the user inputs the characters h, l, and c for higher, lower, and correct, respectively.

For the game to work best, every time your program makes a guess it should choose the midpoint of the remaining possible values. Consider the first example above, in which the user has chosen the number 81:

On the first guess, the possible values are 1 to 100. The midpoint is 50.

The user responds by saying higher

On the second guess the possible values are 51 to 100. The midpoint of 75.

The user responds by saying higher

On the third guess the possible values are 76 to 100. The midpoint is 87.

The user responds by saying lower

On the fourth guess the possible values are 76 to 86. The midpoint is 81.

The user responds correct

Name your program NumberGuesser.cpp and submit it here.

Note: Please consider the following tips in this assignment

Algorithm (10%)

It is the most important part of any programming assignment and should be documented at the top of the source code. Each major block must be commented. Your algorithms must be correct, complete and efficient.

Correctness (70%)

Your program should use the appropriate features of a high-level programming language that are required for the assignment. Your program should give correct output in all situations. Here are some things to check:

1) The output of your program should make it clear that your program works. If for some reason your program does not execute correctly, your output should show that also - I should not have to guess at what is wrong with it.

2) The classes/methods in your program should be well documented:

- Comments at the top of each class and method explaining what task it performs

- Comments alongside/among the code explaining key parts of the algorithm

3) Arguments should be used to send data between methods as appropriate.

4) The use of local variables wherever possible. Make sure you don't pass a variable between methods if it is just being reused within a method.

5) Coding techniques such as using public, static, or global variables unless specifically needed, having more than one return() per method, or using exit() except in the case of fatal errors, results in loss of points.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions