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
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
void getProbsPerSet(int&); // let user choose how many time probs
void getMaxNum(int&); // let user choose randome number of maximun value
void printReport(int, int, int);
void doOneSet(char, int, int&); // do one set of each problem
void doOneProblem(int&); // ask user the answer
void checkAnswer(int, int, int&); // compare the answer if it's right
void generateOperands(char&); // declare which calculation it needs
void CalculateCorrectAnswer(int, int, char, int&); // Find correct answer
int main() {
int probsPerSet,rightnum;
getProbsPerSet(probsPerSet); // calling out getProbsPerSet
srand(static_cast<unsigned>(time(0))); // generate randome number
doOneSet('+', probsPerSet, rightnum); // calling out doOneSet with character +
doOneSet('-', probsPerSet, rightnum); // calling out doOneSet with character -
doOneSet('*', probsPerSet, rightnum); // calling out doOneSet with character *
system("pause");
return 0;
}
void getMaxNum(int& Max) {
cout << "What is the maximum number for this set ? ";
cin >> Max;
cout << endl;
}
void printReport(int Max, int Num, int Right) {
}
void getProbsPerSet(int &Many) { // Many will have fixed value now
cout << "Enter problems per set: ";
cin >> Many; // return Many as typed value
}
void doOneSet(char Function, int Many, int &Right) { // catches int Many, char Function from follwing than do doOneset
int i;
if (Function == '+') { // if when char +
cout << "Set #1" << endl << "----------" << endl;
int Randome;
getMaxNum(Randome); // make user choose with max randome number
for (i = 0; i < Many; i++) { // repeat with following Many
int First, Second, Answer, Final, Number;
cout << "Q" << i + 1 << ") ";
First = rand() % Randome; // generate randome number under what use choose
Second = rand() % Randome; // generate randome number under what use choose
cout << First; // show first generated number
generateOperands(Function); // show which function we are in
cout << Second << " = "; // show second function and =
doOneProblem(Answer); // ask for user to put value as answer
CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
}
}
if (Function == '-') { // if when char -
cout << "Set #2" << endl << "----------" << endl;
int Randome;
getMaxNum(Randome); // make user choose with max randome number
for (i = 0; i < Many; i++) { // repeat with following Many
int First, Second, Answer, Final, Number;
First = rand() % Randome; // generate randome number under what use choose
Second = rand() % Randome; // generate randome number under what use choose
cout << First; // show first generated number
generateOperands(Function); // show which function we are in
cout << Second << " = "; // show second function and =
doOneProblem(Answer); // ask for user to put value as answer
CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
}
}
if (Function == '*') { // if when char *
cout << "Set #3" << endl << "----------" << endl;
int Randome;
getMaxNum(Randome); // make user choose with max randome number
for (i = 0; i < Many; i++) { // repeat with following Many
int First, Second, Answer, Final, Number;
First = rand() % Randome; // generate randome number under what use choose
Second = rand() % Randome; // generate randome number under what use choose
cout << First; // show first generated number
generateOperands(Function); // show which function we are in
cout << Second << " = "; // show second function and =
doOneProblem(Answer); // ask for user to put value as answer
CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
}
}
}
void doOneProblem(int& Ans) {
cin >> Ans;
}
void CalculateCorrectAnswer(int X, int Y, char F, int& A) { // generate correct answer with givin value X,Y with given function F than return A
if (F == '+') {
A = X + Y;
}
if (F == '-') {
A = X - Y;
}
if (F == '*') {
A = X * Y;
}
}
void checkAnswer(int Ans, int A, int &Num) { //compare right answer than user's answer than answer if it's right or wrong
if (Ans == A) {
cout << "Correct" << endl;
Num++;
}
else {
cout << "Incorrect" << endl;
}
}
void generateOperands(char& F) { // just little trick for generate fixed function
cout << " " << F << " ";
}
|