Your task is to write a program to repeatedly generate random multiplications to quiz the user, and keep score.
Generate the two multiplicands (e.g. 6 and 7) and compute the correct answer (42). Then ask the user for his/her answer, and compare it to the correct answer. If the user gets it right, increment the total score. Display the score as a fraction (e.g. 5/8 correct) and a percentage, displayed to the nearest percent (e.g. 63%). Continue generating questions as long as the user indicates he/she would like to keep playing.
Constraint: you must include functions in your program. Include at least these 4 functions, fitting the supplied prototypes:
int NewRandomNumber(int n);
Your function should make use of rand() (part of the cstdlib library) . rand() generates a pseudo-random integer between 1 and 32767. use % and + to convert this integer to an integer between 2 and n.
void MakeQuestion(int n, int& a, int& b, int& atimesb);
answer which were generated in MakeQuestion() and presents the question to the user via cout. It then receives the user’s answer via cin and compares it against the correct answer. If the user’s answer is correct, it returns True. Otherwise, it returns False.
bool UserAnswerIsCorrect(int a, int b, int correctAnswer);
answered correctly, as well as the total number of questions, and computes and displays the user’s score as a fraction and as a percentage.
void PrintScore(int numCorrect, int numAsked);
At the beginning of the program, the user should be able to choose their difficulty by entering a number. For example, if the user enters "4", the computer should only generate questions up to 4 times 4. If the user enters "12", the program should generate questions up to 12 times 12.
Your program should also generate a log file of important data, such as the generated question, the user's response, and the cumulative score. This log should be a comprehensive record of the program run, but should not be a duplication of every user interaction. Further, you must format this log file nicely. For example:
QUIZ PROGRAM LOG FILE
User name: John Smith
Question Response Cumul. Score
===== ==== ===== -- =====
3 * 5 = 15 1/1 (100%)
8 * 2 = 16 16 2/2 (100%)
6 * 9 = 54 45 2/3 (66%)
END OF SESSION
Make sure to fully test your program, and show your testing in your log file. Justify your choice of test cases in your comments.
BONUS: Research and make use of a random number seed, so that the random numbers are different every time the program is run.
MORE BONUS: Research the clock() function in the <ctime> library (http://www.cplusplus.com/reference/ctime/clock/) to implement a timer to measure how long the user takes to answer the question. Maybe you want to reward the user for quick answers, and insult the user if they take too long. Maybe the user has to answer within 10 seconds. Maybe you want to display a countdown timer to show the user how long they have left. Maybe you want to track the time in the log and compare to the last time the user saw the question to see if they are improving. Be creative.
SUPER AMAZING BONUS: Keep a file with a list of users and their score, and each time a user opens the program and enters their name, check against the file to see if they have played before. If they have, continue their score from where they left off.
PRACTICE QUESTION ONLY
You do not have to do this question. This question will not be marked. It is included here as a practice exercise for those of you who feel you need more practice on loops and files. A solution to this question WILL be given to allow you to see how you are doing. You MAY submit your solution to this question, and if you do, it MIGHT count toward a participation mark.
The mean is the sum of all the numbers, divided by how many numbers there are. µ = 1/n∑x
The variance is the sum of the squares of the differences between each number and the mean, divided by how many numbers there are. v = 1/n∑(µ-x)^2
Assignment Writing Help
Engineering Assignment Services
Do My Assignment Help
Write My Essay Services