Here is my code, (output included) and it works but the teacher asked me to do t
ID: 649123 • Letter: H
Question
Here is my code, (output included) and it works but the teacher asked me to do the following changes.
project2_program_code = //GIOVANNI AZPEITIA
//CS10-4524
//SPRG15
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
void getProbsPerSet(int &);
void printReport(int, int, int, int);
void doOneSet(char, int, int&);
int main()
{
int probsPerSet;
int set1Correct, set2Correct, set3Correct;
srand(time(0));
int nset;
getProbsPerSet(probsPerSet);
doOneSet('+', probsPerSet, set1Correct);
doOneSet('-', probsPerSet, set2Correct);
doOneSet('*', probsPerSet, set3Correct);
printReport(probsPerSet, set1Correct, set2Correct, set3Correct);
return 0;
}
void getProbsPerSet(int &nset){
cout << "Enter problems per set: ";
cin >> nset;
}
void printReport(int nset, int set1Correct, int set2Correct, int set3Correct){
int total = set1Correct + set2Correct + set3Correct;
cout << "Set#1: You got " << set1Correct << " correct out of " << nset << " for " << (set1Correct * 100 / (nset)) << "%" << endl;
cout << "Set#2: You got " << set2Correct << " correct out of " << nset << " for " << (set2Correct * 100 / (nset)) << "%" << endl;
cout << "Set#3: You got " << set3Correct << " correct out of " << nset << " for " << (set3Correct * 100 / (nset)) << "%" << endl;
cout << "Overall you got " << total << " correct out of " << nset * 3 << " for " << ((total * 100 / (3 * nset))) << "%" << endl;
}
void doOneSet(char problemType, int nset, int &correct)
{
correct = 0;
int num1 = 0, num2 = 0, maxNum = 100;
int correctAnswer = 0, userInput = 0;
bool isCorrect = false;
switch (problemType)
{
case '+':
cout << endl << " Set #1" << endl;
cout << "-------" << endl << endl;
cout << "What is the maximum number for this set? ";
cin >> maxNum;
cout << endl;
for (int count = 1; count <= nset; count++)
{
num1 = rand() % (maxNum + 1);
num2 = rand() % (maxNum + 1);
cout << num1 << " + " << num2 << " = ";
cin >> userInput;
correctAnswer = num1 + num2;
if (userInput == correctAnswer)
isCorrect = true;
else
isCorrect = false;
if (isCorrect){
cout << "correct" << endl;
correct++;
}
else
cout << "incorrect" << endl;
} break;
case '-':
cout << endl << " Set #2" << endl;
cout << "-------" << endl << endl;
cout << "What is the maximum number for this set? ";
cin >> maxNum;
cout << endl;
for (int count = 1; count <= nset; count++)
{
num1 = rand() % (maxNum + 1);
num2 = rand() % (maxNum + 1);
cout << num1 << " - " << num2 << " = ";
cin >> userInput;
correctAnswer = num1 - num2;
if (userInput == correctAnswer)
isCorrect = true;
else
isCorrect = false;
if (isCorrect){
cout << "correct" << endl;
correct++;
}
else
cout << "incorrect" << endl;
}
break;
case '*':
cout << endl << " Set #3" << endl;
cout << "-------" << endl << endl;
cout << "What is the maximum number for this set? ";
cin >> maxNum;
cout << endl;
for (int count = 1; count <= nset; count++)
{
num1 = rand() % (maxNum + 1);
num2 = rand() % (maxNum + 1);
cout << num1 << " * " << num2 << " = ";
cin >> userInput;
correctAnswer = num1*num2;
if (userInput == correctAnswer)
isCorrect = true;
else
isCorrect = false;
if (isCorrect){
cout << "correct" << endl;
correct++;
}
else
cout << "incorrect" << endl;
}
break;
}
}
project2_program_output = Enter problems per set: 3
Set #1
-------
What is the maximum number for this set? 100
20 + 61 = 81
correct
61 + 27 = 88
correct
66 + 79 = 148
incorrect
Set #2
-------
What is the maximum number for this set? 90
58 - 13 = 45
correct
5 - 14 = -11
incorrect
35 - 64 = -29
correct
Set #3
-------
What is the maximum number for this set? 20
13 * 12 = 156
correct
11 * 0 = 0
correct
12 * 10 = 120
correct
Set#1: You got 2 correct out of 3 for 66%
Set#2: You got 2 correct out of 3 for 66%
Set#3: You got 3 correct out of 3 for 100%
Overall you got 7 correct out of 9 for 77%
Process returned 0 (0x0) execution time : 83.656 s
Press any key to continue.
Looks like you have the math tutor completed but with three functions instead of the nine required functions as shown in the structure diagram on the Project#2 information sheet.
Could you further decompose doOneSet to include calls to printHeader > getMaxNum > doOneProblem and doOneProblem should have calls to getNumbers > calcCorrectAnswer> checkAnswer. The correctCount captured in the lower level functions are passed back up to set1Correct ,set2Correct , set3Correct as you have already done in this version.
It is a bit more work, working through the needed parameters in each one of the remaining six functions and you might find the attached class handout with nine function prototypes helpful as you further restructure your source code to meet the program specifications.
I would also recommend including more documentation related to functions, such as data flow comments in the parameter lists and pre and post conditions directly below each function headings. You will find an example of function documentation in the class hand out provided or check the link on the project information sheet:
//Math Tutor HINT ...sample function prototypes with related formal parameters and function documentation,
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
// ***function prototypes per program specification and structure design**************************
void getProbsPerSet (/*out*/ int& numProbs);
void doOneSet (/* in */ char problemType,/* in */ int numProbs, /*out */ int& correctCount);
void getMaxNum (/* out */int& maxNum);
void printHeader (/* in */ char problemType);
void doOneProblem (/* in */char problemType,/* in */ int maxNum,/*out */ bool& isCorrect);
void generateOperands (/* out */int& num1, /*out */int& num2,/* in */ int maxNum);
void calcCorrectAnswer (/* in */ char problemType,/* in */ int num1, /* in */int num2, /* inout*/ int& answer);
void checkAnswer (/* in */int num1,/* in */ int num2, /*out */bool& isCorrect);
void printReport (/* in */int probsPerSet, /* in */ int set1Correct, /* in */int set2Correct, /* in */int set3Correct);
int main()
{
//initial variables needed for parameter passing to other functions
int probsPerSet=0;
int set1Correct=0,set2Correct=0,set3Correct=0;
srand(time(0));
getProbsPerSet (probsPerSet);
doOneSet ('+', probsPerSet, set1Correct);
//HINT: other similar function calls to doOneSet with one single argument changed
printReport (probsPerSet, set1Correct, set2Correct, set3Correct);
return 0;
}
void getProbsPerSet (/*out*/ int& numProbs)
// This function prompts the user for the number of problems to
// complete in each set. The number must be between 3 and 10
// Preconditions:
// User has been prompted for and supplied the value of numProbs
// and a blank line has been printed.
// Postconditions:
// User has provided a valid value now stored in numProbs
{
cout << "Enter problems per set: ";
cin >> numProbs;
cout << endl;
}
void doOneSet (/* in */ char problemType,/* in */ int numProbs, /*out */ int& numCorrect)
// This function prints a header for a set of problems, gets the
// maximum value of the random numbers to be generated for problems,
// and tracks the number of correct answers generated, which is
// returned to the calling function via 'numCorrect'.
// Preconditions:
// problemType and numProbs are assigned. problemType is '+',
// '-' or '*'.
// Postconditions:
// User has been provided 'numProbs' problems to solve of a type
// defined by 'problemType'. 'numCorrect' contains the number of
// problems correctly answered by the user.
{
int i;
int maxNum;
bool isCorrect;
//your code here
}
void getMaxNum (/* out */int& maxNum)
{
//your code here
}
void printHeader (/* in */ char problemType)
{
//your code here
}
void doOneProblem (/* in */char problemType,/* in */ int maxNum,/*out */ bool& isCorrect)
{
//your code here
}
void generateOperands (/* out */int& num1, /*out */int& num2,/* in */ int maxNum)
{
//your code here
}
void calcCorrectAnswer (/* in */ char problemType,/* in */ int num1, /* in */int num2, /* inout*/ int& answer)
{
//your code here
}
void checkAnswer (/* in */int num1,/* in */ int num2, /*out */bool& isCorrect)
{
//your code here
}
void printReport (/* in */int probsPerSet, /* in */ int set1Correct, /* in */int set2Correct, /* in */int set3Correct)
// This function prints a report detailing the user's success rate
// at correctly answering arithmetic problems, posed in three sets.
// It prints the user's score and percentage correct for each set,and overall.
{
int set1Percent;
int totalPercent;
set1Percent = (100 * set1Correct) / probsPerSet;
cout << endl;
cout << "Set#1: You got " << set1Correct << " correct out of "<< probsPerSet << " for " << set1Percent << "%" << endl;
// your code here
}
Notes:
Note: The doOneProblem function does exactly one problem, not one *type* of problem!!
Please change getNumbers to generateOperands
CheckAnswer is the function that writes either "correct" or "incorrect"
You will receive a 0 on this assignment if you use global variables, arrays or structs
Turn in only phase VI, your final product. Provide sample output.
You will lose points if the code you put in one of your functions does not correspond to the name of the function given in the structure diagram.
Please make sure to place a comment near each of your function definitions, use good decomposition, separate your functions with at least 1 inches of whitespace and DO NOT use global variables.
I would appreciate any help
Here is my code, (output included) and it works but the teacher asked me to do the following changes.Looks like you have the math tutor completed but with three functions instead of the nine required functions as shown in the structure diagram on the Project#2 information sheet. Here is my code, (output included) and it works but the teacher asked me to do the following changes. What is the maximum number for this set? 90 58 - 13 = 45 correct 5 - 14 = -11 incorrect 35 - 64 = -29 correct Set #3 ------- What is the maximum number for this set? 20 13 * 12 = 156 correct 11 * 0 = 0 correct 12 * 10 = 120 correct Set#1: You got 2 correct out of 3 for 66% Set#2: You got 2 correct out of 3 for 66% Set#3: You got 3 correct out of 3 for 100% Overall you got 7 correct out of 9 for 77% Process returned 0 (0x0) execution time : 83.656 s Press any key to continue. Looks like you have the math tutor completed but with three functions instead of the nine required functions as shown in the structure diagram on the Project#2 information sheet. Could you further decompose doOneSet to include calls to printHeader > getMaxNum > doOneProblem and doOneProblem should have calls to getNumbers > calcCorrectAnswer> checkAnswer. The correctCount captured in the lower level functions are passed back up to set1Correct ,set2Correct , set3Correct as you have already done in this version. It is a bit more work, working through the needed parameters in each one of the remaining six functions and you might find the attached class handout with nine function prototypes helpful as you further restructure your source code to meet the program specifications. I would also recommend including more documentation related to functions, such as data flow comments in the parameter lists and pre and post conditions directly below each function headings. You will find an example of function documentation in the class hand out provided or check the link on the project information sheet:Explanation / Answer
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
void getProbsPerSet(int &);
void printReport(int, int, int, int);
void doOneSet(char, int, int&);
int main()
{
int probsPerSet;
int set1Correct, set2Correct, set3Correct;
srand(time(0));
int nset;
getProbsPerSet(probsPerSet);
doOneSet('+', probsPerSet, set1Correct);
doOneSet('-', probsPerSet, set2Correct);
doOneSet('*', probsPerSet, set3Correct);
printReport(probsPerSet, set1Correct, set2Correct, set3Correct);
return 0;
}
void getProbsPerSet(int &nset){
cout << "Enter problems per set: ";
cin >> nset;
}
void printReport(int nset, int set1Correct, int set2Correct, int set3Correct){
int total = set1Correct + set2Correct + set3Correct;
cout << "Set#1: You got " << set1Correct << " correct out of " << nset << " for " << (set1Correct * 100 / (nset)) << "%" << endl;
cout << "Set#2: You got " << set2Correct << " correct out of " << nset << " for " << (set2Correct * 100 / (nset)) << "%" << endl;
cout << "Set#3: You got " << set3Correct << " correct out of " << nset << " for " << (set3Correct * 100 / (nset)) << "%" << endl;
cout << "Overall you got " << total << " correct out of " << nset * 3 << " for " << ((total * 100 / (3 * nset))) << "%" << endl;
}
void doOneSet(char problemType, int nset, int &correct)
{
correct = 0;
int num1 = 0, num2 = 0, maxNum = 100;
int correctAnswer = 0, userInput = 0;
bool isCorrect = false;
switch (problemType)
{
case '+':
cout << endl << " Set #1" << endl;
cout << "-------" << endl << endl;
cout << "What is the maximum number for this set? ";
cin >> maxNum;
cout << endl;
for (int count = 1; count <= nset; count++)
{
num1 = rand() % (maxNum + 1);
num2 = rand() % (maxNum + 1);
cout << num1 << " + " << num2 << " = ";
cin >> userInput;
correctAnswer = num1 + num2;
if (userInput == correctAnswer)
isCorrect = true;
else
isCorrect = false;
if (isCorrect){
cout << "correct" << endl;
correct++;
}
else
cout << "incorrect" << endl;
} break;
case '-':
cout << endl << " Set #2" << endl;
cout << "-------" << endl << endl;
cout << "What is the maximum number for this set? ";
cin >> maxNum;
cout << endl;
for (int count = 1; count <= nset; count++)
{
num1 = rand() % (maxNum + 1);
num2 = rand() % (maxNum + 1);
cout << num1 << " - " << num2 << " = ";
cin >> userInput;
correctAnswer = num1 - num2;
if (userInput == correctAnswer)
isCorrect = true;
else
isCorrect = false;
if (isCorrect){
cout << "correct" << endl;
correct++;
}
else
cout << "incorrect" << endl;
}
break;
case '*':
cout << endl << " Set #3" << endl;
cout << "-------" << endl << endl;
cout << "What is the maximum number for this set? ";
cin >> maxNum;
cout << endl;
for (int count = 1; count <= nset; count++)
{
num1 = rand() % (maxNum + 1);
num2 = rand() % (maxNum + 1);
cout << num1 << " * " << num2 << " = ";
cin >> userInput;
correctAnswer = num1*num2;
if (userInput == correctAnswer)
isCorrect = true;
else
isCorrect = false;
if (isCorrect){
cout << "correct" << endl;
correct++;
}
else
cout << "incorrect" << endl;
}
break;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.