DUE: Tuesday, April 27 before 11:00pm
Collaboration is strictly FORBIDDEN. Programs must represent YOUR OWN original work. Sharing code or team-coding are not allowed for this assignment. Copying code from ANY source (any book, current or past students, past solutions, the web, etc.) is not allowed. Cooperation to the extent of helping to debug, or discussing the general approach to solving the problem is encouraged, but should never involve communicating code or even pseudo-code or explicit algorithms. Your code must be unique -- if it is not, we will find out, and will treat it as a case of flagrant academic dishonesty.
You must turn in a C++ source file (and only a C++ source file). The name for your source file should be as3.cpp.
Turn in online to the appropriate folder for your lab section (e.g., as3_sec20 for students enrolled in lab section 20). If you turn your assignment in to the wrong folder, your assignment may not be graded. If it is graded, you will lose 2 pts (out of 10).
Remember to include the header as it is in the template provided on the class website.
Design a program that allows the a user to practice multiplication and addition. The program should ask the user how many questions they want and whether they want to practice addition or multiplication. Then the program should ask that many questions. For each question, either output they got the correct answer or, if they got it wrong, output the correct answer. When done asking the requested number of questions, output the percentage of correct answers. Finally, the program should repeat if the user desires.
We have provided the main function of the program here, as3.cpp. You need only write the definitions of the add and mult functions called from within main. Each function is passed the number of questions to ask and should return the percentage of correct answers. DO NOT CHANGE THE MAIN FUNCTION. The add and mult function declarations are also included. Remember, the header of each function definition needs to match the declaration exactly.
The functions will need to generate random numbers for each calculation.
The add function should choose numbers between 0 and 100, and the mult function
should choose numbers between 0 and 12. Pg 965 of the textbook talks about
the rand() and srand() functions used in assignment 2 to generate a random
number. Basically, put
srand( time(0) );
at the top of your function. Then call the rand() function anytime you need
a random number.
rand_one = rand() % 101;
generates a random integer between 0 and 100 and assigns it to the variable
rand_one.
rand_one = rand() % 13;
generates a random integer between 0 and 12 and assigns it to the variable
rand_one.
The following are 2 different sample outputs to help you design your program.
Sample 1
This program helps you learn addition and multiplication. Enter the number of questions you would like: 3 Would you like to practice multiplication or addition? (+ or *)+ 71 + 1 = 72 Correct! 90 + 22 = 122 Sorry, the correct answer is 112 37 + 81 = 99 Sorry, the correct answer is 118 You got 33% of the questions correct. Would you like to go again? (y or n) n
Sample 2
This program helps you learn addition and multiplication. Enter the number of questions you would like: 4 Would you like to practice multiplication or addition? (+ or *)* 7 * 6 = 42 Correct! 11 * 9 = 99 Correct! 7 * 12 = 77 Sorry, the correct answer is 84 2 * 3 = 6 Correct! You got 75% of the questions correct. Would you like to go again? (y or n) y Enter the number of questions you would like: 1 Would you like to practice multiplication or addition? (+ or *)+ 79 + 79 = 45 Sorry, the correct answer is 158 You got 0% of the questions correct. Would you like to go again? (y or n) n
DO NOT CHANGE THE MAIN FUNCTION IN ANY WAY.
If the program does not compile, 3 pts will be deducted from the final score. Compile your code often. Only write a small portion of code before checking that it still compiles. This way when you get a syntax error, you can be fairly certain the error is in the part you just wrote.
2 pts: function syntax
- (1 pt) Header
- (1 pt) Body
2 pts: loops in functions
- (1 pt) Loops correct number of times
- (1 pt) Correct syntax
3 pts: correct output
- (1 pt) Outputs arithmetic question
- (1 pt) Outputs "correct" or correct answer if wrong
- (1 pt) Outputs correct percentage
1 pt: Header info (use report template header on syllabus)
2 pts: Style
- (.5 pts) Good variable names
- (.5 pts) Proper indentation/spacing
- (.5 pts) Good comments
- (.5 pts) No line wraps