1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
//********************************
// This program will ask the user to answer a series of
//arithmetic questions and will report on how the user performs.
#include <iostream>
#include <ctime> // Will be used by the srand function for time
#include <cstdlib> // will allow for random numbers to be generated.
using namespace std;
void getProbsPerSet(int& numProbs);
// The following functions will have inputs
void doOneSet( char problemType,int numProbs,int& correctCount);
void getMaxNum(int &maxNum); // Will need inputs
void printHeader(char problemType);
void doOneProblem(char problemType, int& MaxNum, int & correctCount);
void generateOperands(int& firstNum, int& secondNum, int maxNum);
void calcCorrectAnsw(char problemType, int firstNumber, int secondNum, int& answer);
void checkAnswer (int correctAnsw,int answer, int&correctCount);
void printReport(int probsPerSet, int set1Correct, int set2Correct, int set3Correct);
int main()
{
int probsPerSet;
int set1Correct,set2Correct,set3Correct;
srand(time(0)); // will initialize the random number generator
getProbsPerSet(probsPerSet);
doOneSet('+',probsPerSet,set1Correct);
doOneSet('-',probsPerSet,set2Correct);
doOneSet('*',probsPerSet,set3Correct);
return 0;
}
void getProbPerSet(int& numProbs)
{
do
{
cout<< " Enter the number of problems per set you would like (between 3 and 10):";
cin >> numProbs;
}
while (numProbs< 3 || numProbs > 10); // Restrict the user to no less than 3 sets but no more than 10
}
void doOneSet( char problemType,int numProbs,int& correctCount);
// declare variables
int maxNum;
// function will call:
printHeader(char problemType);
getMaxNum(maxNum);
for(int = 1; i <= numProbs; i++)
{
doOneProblem(sign, maxNum ,correctCount);
}
void printHeader(char problemType);
{
switch(problemType)
{
case '+' : cout << "\nSet Number One"<< endl
<< "----------" << endl;
break;
case '*' : cout << "\n Set Number Two"<< endl
<< "----------" << endl;
break;
case '-' : cout << "\n Set Number Two"<< endl
<< "----------" << endl;
break;
default : cout << "incorrect";
}
}
void getMaxNum(int &maxNum);
{
cout << " What is the maximum number for this set?:";
cin >> maxNum
}
void doOneProblem(char problemType, int& MaxNum, int & correctCount);
{
// assign variables
int firstNum, secondNum; // random numbers the program will be using
int answer;
int correctAnswer = 0;
getNumbers(firstNum, secondNum, maxNum);
cout << firstNum <<" " << problemType << " " << secondNum << " = ";
cin >> userAnswer;
void calcCorrectAnsw(char problemType, int firstNumber, int secondNum, int& answer);
void checkAnswer (int correctAnsw,int answer, int&correctCount);
}
void getMaxNum(int &maxNum);
{
value1 = rand() % (max_range +1);
value2 = rand() % (max_range +1);
}
void calcCorrectAnsw(char problemType, int firstNumber, int secondNum, int& answer);
switch(arithmProblemType)
{
case '+' : value3 = value1 + value2;
break;
case '-' : value3 = value1 - value2;
break;
case '*' : value3 = value1 * value2;
break;
default : cout << "incorrect";
}
}
void checkAnswer (int correctAnsw,int answer, int&correctCount);
{
if(userValue == correctValue)
{
cout << "correct" << endl;
countCorrect++;
}
else
cout << "incorrect" << endl;
}
void printReport(int probsPerSet, int set1Correct, int set2Correct, int set3Correct);
{
// explicit type casting is performed for the percentage indicator.
cout << "\nSet #1: You got " << set1Correct << " correct out of "
<< probsPerSet << " for " << int(set1Correct * 100.0 / probsPerSet + 0.5)
<< "%." << endl;
cout << "Set #2: You got " << set2Correct << " correct out of "
<< probsPerSet << " for " << int(set2Correct * 100.0 / probsPerSet + 0.5)
<< "%." << endl;
cout << "Set #3: You got " << set3Correct << " correct out of "
<< probsPerSet << " for " << int(set3Correct * 100.0 / probsPerSet + 0.5)
<< "%." << endl;
cout << "Overall you got " << set1Correct + set2Correct + set3Correct << " out of "
<< probsPerSet * 3 << " for "
<< int(((set1Correct + set2Correct + set3Correct) * 100.0 ) / (probsPerSet * 3) + 0.5)
<< "%." << endl;
}
|