Question
Help me write out second half of c++ program. This program generates addition, subtraction and mulitplication problems for the user. I have a program I
Help me write out second half of c++ program. This program generates addition, subtraction and mulitplication problems for the user. I have a program I will put below.
I still need to:
1) Ask the user to enter the number of problems per set using getProbsPerSet
2) Create a header for each set using printHeader
3) Ask the user to enter a maximum number for each set using getMaxNum
4) Generate a report with the total number of correct answers and a percentage using printReport
Below are the instructions for the assignment, under that you will find what I already have started of the assignment
Phase 4: Now you are ready to let the user specify how many problems per set. (Recall that a set is a group of problems all of the same type. In this program we are doing three sets: one set of addition, one set of subtraction, and one set of multiplication. This means that, for example, if the problems per set is 7, there will be a total of 21 problems given.) Ask the user to enter the number of problems per set at the very beginning of the program, so that all three sets have the same number of problems per set. Now your main() function will look exactly like this except that you may add variable declarations in the indicated location:
int main() {srand(static_cast (time(0))); getProbsPerSet(probsPerSet); doOneSet('+', probsPerSet); doOneSet('-', probsPerSet); doOneSet('*', probsPerSet); }
For this phase you should also add a header at the beginning of each set, as illustrated in the following sample output for this phase. For purposes of the header, you should assume that the addition problems will always be set #1, the subtraction problems set #2, and the multiplication problems set #3.
Enter problems per set: 3 Set #1 ---------- 45 + 21 = 66 correct 0 + 100 = 100 correct 54 + 23 = 67 incorrect Set #2 ---------- 59 - 19 = 40 correct 19 - 84 = -29 incorrect 0 - 65 = -65 correct Set #3 ---------- 0 * 87 = 0 correct 45 * 84 = 398 incorrect 8 * 37 = 873 incorrect
Phase 5: Now let the user specify maxNum, the maximum number to be used for each set. This means that instead of choosing numbers between 0 and 100 (inclusive) for each problem, the computer will be choosing numbers between 0 and maxNum (inclusive). You must allow the user to enter a different maximum number for each set. This won't change the main() function, since you need to ask it again before each set. It will be done near the beginning of your doOneSet function. Here's the sample screen output:
Enter problems per set: 3 Set #1 ---------- What is the maximum number for this set? 100 45 + 21 = 66 correct 0 + 100 = 100 correct 54 + 23 = 67 incorrect Set #2 ---------- What is the maximum number for this set? 90 59 - 19 = 40 correct 19 - 84 = -29 incorrect 0 - 65 = -65 correct Set #3 ---------- What is the maximum number for this set? 20 0 * 18 = 0 correct 15 * 4 = 398 incorrect 8 * 17 = 873 incorrect
Phase 6: Now you need to keep track of how the user is doing. after the user has attempted all of the problems, your program should write a report that says how many the user got right on each set out of how many and for what percent. The report must also indicate the overall figures. Here's a sample screen output:
Enter problems per set: 3 Set #1 ---------- What is the maximum number for this set? 100 45 + 21 = 66 correct 0 + 100 = 100 correct 54 + 23 = 67 incorrect Set #2 ---------- What is the maximum number for this set? 90 59 - 19 = 40 correct 19 - 84 = -29 incorrect 0 - 65 = -65 correct Set #3 ---------- What is the maximum number for this set? 20 0 * 18 = 0 correct 15 * 4 = 398 incorrect 8 * 17 = 873 incorrect Set#1: You got 2 correct out of 3 for 66.7% Set#2: You got 2 correct out of 3 for 66.7% Set#3: You got 1 correct out of 3 for 33.3% Overall you got 5 correct out of 9 for 55.6%
Note that the results must be rounded to the nearest tenth. To round your results, just use
cout << fixed << setprecision(1) << yourPercentCorrectVariable;
Your main() function for phase 6 must look like this, except that you may add variable declarations and arguments in the indicated locations:
int main() {srand(static_cast (time(0))); getProbsPerSet( ); doOneSet( ); doOneSet( ); doOneSet( ); printReport( ); }
Notice that you may send no more than 3 arguments to doOneSet. Although main() will need three separate variables to keep track of the number of problems answered correctly in each set, your doOneSet function will have only one parameter that keeps track of the number of problems answered correctly in the current set. It will be up to main() to get that information into the correct variable.
So Far..
#include
#include
#include
#include
void doOneSet(char op);
void doOneProblem(char op);
void generateOperands(int &num1, int &num2);
void calculateCorrectAnswer(int &num1, int &num2, int &result, char op);
void checkAnswer(int &result, int &answer);
using namespace std;
int main() {
srand(static_cast
doOneSet('+');
doOneSet('-');
doOneSet('*');
system("pause");
return 0;
}
void doOneSet(char op) {
for (int i = 0; i<5; i++) {
doOneProblem(op);
}
}
void doOneProblem(char op) {
int num1, num2, result, answer;
generateOperands(num1, num2);
calculateCorrectAnswer(num1, num2, result, op);
cin >> answer;
checkAnswer(result, answer);
}
void generateOperands(int &num1, int &num2) {
num1 = rand() % 101;
num2 = rand() % 101;
}
void calculateCorrectAnswer(int &num1, int &num2, int &result, char op) {
switch (op) {
case '+':
result = num1 + num2;
cout << num1 << "+" << num2 << "=";
break;
case '-':
result = num1 - num2;
cout << num1 << "-" << num2 << "=";
break;
case '*':
result = num1 * num2;
cout << num1 << "*" << num2 << "=";
break;
}
}
void checkAnswer(int &result, int &answer) {
if (answer == result) {
cout << "correct" << endl;
}
else {
cout << "incorrect" << endl;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started