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
|
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
using namespace std;
const int NUM_QUESTIONS = 20;
//We need to create a class that will have an answers array of 20
//characters, which holds the corrrect test answers.
//The class will have two public member functions, setKey and grade.
class TestGrader
{
private:
char answerKey[NUM_QUESTIONS];
char userAnswers[NUM_QUESTIONS];
public:
void setKey(char correctanswers[NUM_QUESTIONS])
{
for (int x = 0; x < NUM_QUESTIONS; x++)
{
correctanswers[x] == answerKey[x];
}
}
bool grade(char answers)
{
if (toupper(answers) != 'A' && toupper(answers) != 'B' && toupper(answers) != 'C' &&
toupper(answers) != 'D' &&)
{
cout << "Please enter a valid answer" << endl;
return false;
}
};
int main()
{
TestGrader grader1;
int correctAnswers;
char answerKey[20] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C',
'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' };
char userAnswers[NUM_QUESTIONS];
for (int i = 0; i < NUM_QUESTIONS; i++)
{
do
{
cout << "Enter your answer for question #" << i + 1 << " ";
cin >> userAnswers[i];
} while (grader1.grade(userAnswers));
grader1.setKey(answerKey)
}
return;
}
|