Math tutor program


Category: You will Instantly receive a download link for .zip solution file upon Payment


5/5 - (2 votes)

Problem 1: Start with your math tutor program from Exercise 4, and first fix any errors
from the previous submission.
Add a new loop and a menu so that the user can practice with more than one problem
each time that they run the program. Most of your existing code will be placed within the
loop. The only code which will not be inside the loop is your variable declarations and
seeding the random number generator at the top (these only need to be done once), and
the system pause and return 0 at the bottom.
You will present the user with a menu with choices to do addition, subtraction, or quit. If
they choose quit, you can exit the loop. Otherwise, present them with a math problem to
solve. As in Exercise 4, let them enter their answer and keep prompting them if they got
it wrong.
If they choose subtraction, make sure that the problem does not come out negative! You
can either swap the contents of the variables to ensure you subtract the smaller number
from the larger, or use a loop to generate new numbers until the result is not negative.
Remember to assign new values to your variables each time through the loop, so that they
always see a different problem! Also, try to avoid duplicating numerous lines of code. If
they choose addition or subtraction, most of the code is the same (roll some random
numbers, display the first number, display a + or – sign, display the second number, draw
a line of dashes, read their input, compare it to the correct answer, etc). About the only
parts that are different are:
a) Whether you need to regenerate a number if the first number is less than the second
b) Whether to display a + or – sign
c) How you calculate the correct answer
Create at least one function, outside of main(), in your program. Some ideas where you
could create a function include:
– Displaying menu and getting user’s choice
– Validating the user’s choice
– Checking if the user’s answer to the problem is correct
– Etc…
Problem 3: (15 points) Write a complete program that can be used to generate a practice
math problem for a young student. The program should display two random numbers
between 1 and 200 to be added, similar to this:
+ 168
The program pauses while the student works on the problem. When the student is ready
to check their answer, they can enter it under the problem.
+ 168
After receiving the user’s answer, compare it to the correct value. If they are correct,
congratulate them and exit the program. If they are incorrect, display a message
indicating that the answer is incorrect and prompt them to try again. Continue to prompt
them ( in a loop) until they enter the correct value.
Note that your output should line up in columns as shown above. The input from the user,
however, does not have to align perfectly with the other numbers in the problem.
You should use a named constant for limiting the range of numbers returned by the
random number generator, and that named constant should contain all capital letters (and
possibly underscore).
One aspect of random numbers is that a computer doesn’t really generate “random”
numbers. It has an algorithm, a set of steps that it follows, to generate them. For this
reason, computer-generated random numbers are often referred to as “pseudo-random”.
Unfortunately, C++ generates the same pseudo-random numbers every time the program
is run, making this a somewhat useless tutor! We can, however, “seed” the random
number generator, but what value do we seed it with? If we seed it with the same value
every time (such as 123), we still get the same pseudo-random numbers every time.
What we need is a number, to use as a seed, that changes…
To make your program generate different values you have to do two things: 1) Add the
following line of code at the top of your file, along with your other include(s):
2) Inside of your main() function, at the top, before you call rand(), add the
following lines of code; you only need to do this once, at the beginning of main():
// Seed the random number generator from the time of day.
srand( (unsigned int) time( NULL ) );
What this does is use the “current time” as the seed for the random number generator. If
the program is run at a different time, it generates a different pseudo-random sequence.