please help. please read the structure carefully because all the phases should f
ID: 3538937 • Letter: P
Question
please help.
please read the structure carefully because all the phases should follow the format. thank you.
Phase 1: Your main function for phase I must look exactly like this:
You must write the function doOneSet which will, for now, write out 5 addition problems. All of the numbers printed should be between 0 and 100, inclusive. Here is a sample output for this phase:
The numbers that are produced for these problems must be generated randomly by the computer. The numbers in the sample output are given only as an example. Refer to lesson 7.3 for more information about generating random numbers.
Phase 2: Change your doOneSet function so that instead of just writing out the problems it also allows the user to enter an answer, and then tells the user whether the answer was correct or not. Do not change your main function. Here is the sample output for this phase (user input is indicated here by using bold font. It won't be bold in your own output):
Before you move on to phase 3, refer to the structure diagram at the end of this document and make sure that you have adhered to it for all of the functions indicated there for phase 2. This will probably mean dividing your doOneSet function up into functions, if you haven't done it already.
Phase 3: Now you will change your doOneSet function so that it will work for either addition, subtraction, or multiplication. For the purposes of this assignment, a set of problems is defined to be a group of problems that are all of the same type (all addition, all subtraction, or all multiplication). After completing this phase your program will give 5 addition problems, 5 subtraction problems, and 5 multiplication problems, for a total of 15 problems. Your main function must look exactly like this:
The parameter tells doOneSet whether to do addition, subtraction, or multiplication. Notice that there is exactly one doOneSet function definition, not three! Here is the sample output for this phase:
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:
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.
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:
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 percent must be rounded to the nearest integer, as illustrated in the sample output. The report must also indicate the overall figures. Here's a sample screen output:
Your main function for phase 6 must look like this, except that you may add variable declarations and arguments in the indicated locations:
Notice that you may send no more than 3 arguments to doOneSet. Hint: 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.
The following structure diagram includes every function that you will have in your program. You should have no more and no fewer, and you should use the names that have been indicated here. Please also read the notes below the structure diagram very carefully.
Notes:
Explanation / Answer
please rate - thanks
any problems, let me know I will fix it
(this took a long time to do)
#include <iostream>
#include <ctime>
using namespace std;
void doOneSet(char,int,int&);
bool doOneProblem(char,int);
void generateOperands(int&,int&,int);
int calculateCorrectAnswer(int,int,char);
bool checkAnswer(int,int);
void getProbsPerSet(int&);
void printHeader(char);
int getMaxNum();
void printReport(int,int,int,int);
int main()
{int probsPerSet,correctAdd=0,correctSub=0,correctMult=0;
srand(time(0));
getProbsPerSet(probsPerSet);
doOneSet('+', probsPerSet,correctAdd);
doOneSet('-', probsPerSet,correctSub);
doOneSet('*', probsPerSet,correctMult);
printReport(probsPerSet,correctAdd,correctSub,correctMult);
system("pause");
}
void printReport(int set,int add,int sub,int mult)
{
cout<<"Set # 1: You got "<<add<<" out of "<<set<<" for "<<(int)(add/(double)set*100.)<<"% ";
cout<<"Set # 2: You got "<<sub<<" out of "<<set<<" for "<<(int)(sub/(double)set*100.)<<"% ";
cout<<"Set # 3: You got "<<mult<<" out of "<<set<<" for "<<(int)(mult/(double)set*100.)<<"% ";
}
void printHeader(char op)
{int set;
switch(op)
{{case '+': set=1; break;
case '-': set=2; break;
case '*': set=3; break;
}
}
cout<<"Set # "<<set<<" ------- ";
}
int getMaxNum()
{int max;
cout<<"What is the maximum number for this set? ";
cin>>max;
return max;
}
void doOneSet(char op,int n,int& correct)
{int i,max;
printHeader(op);
max=getMaxNum();
for(i=0;i<n;i++)
if(doOneProblem(op,max))
correct++;
}
bool doOneProblem(char op,int max)
{int ans,user,op1,op2;
generateOperands(op1,op2,max);
ans=calculateCorrectAnswer(op1,op2,op);
cout<<op1<<" "<<op<<" "<<op2<<" = ";
cin>>user;
if(checkAnswer(ans,user))
return true;
else
return false;
}
void generateOperands(int& op1,int& op2,int max)
{op1=rand()%(max+1);
op2=rand()%(max+1);
}
int calculateCorrectAnswer(int op1,int op2,char op)
{switch(op)
{case '+': return op1+op2;
case '-': return op1-op2;
default: return op1*op2;
}
}
bool checkAnswer(int ans,int user)
{if(ans==user)
{cout<<"correct ";
return true;
}
else
{ cout<<"incorrect ";
return false;
}
}
void getProbsPerSet(int& probsPerSet)
{cout<<"Enter problems per set: ";
cin>>probsPerSet;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.