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
|
#include <iostream>
using namespace std;
void grade(char studA, char corrA, int size);
const int testSize = 10;
int main()
{
char correctAnswers[testSize] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D' }, studentAnswers[testSize];
for (int counter = 0; counter < testSize; counter++)
{
cout << "Enter student's answer to question " << counter + 1 << ": " << endl;
cin >> studentAnswers[counter];
if (studentAnswers[counter] != 'A' || 'B' || 'C' || 'D')
{
int exitCounter = 2;
cout << "\nInvlaid data. A, B, C and D are the only valid inputs. " << exitCounter << " attempts remaining." << endl;
exitCounter--;
if (exitCounter == 0)
{
cout << "\nGOOD BYE" << endl << endl;
return 0;
}
}
}
grade(studentAnswers[testSize], correctAnswers[testSize], testSize);
return 0;
}
void grade(char studA, char corrA, int size)
{
int correctCounter = 0, incorrectCounter = 0;
for (int counter = 0; counter < size; counter++)
{
if (studA[counter] == corrA[counter])
correctCounter++;
else
incorrectCounter++;
}
if (correctCounter >= 8)
{
cout << "Congratulations!" << endl;
cout << "You have passed exam." << endl;
cout << "Total number of correct answers: " << correctCounter<< endl;
cout << "Total number of incorrect answers: " << incorrectCounter << endl << endl;
}
else
{
cout << "Sorry, you have not passed exam!" << endl;
cout << "Total number of correct answers: " << correctCounter << endl;
cout << "Total number of incorrect answers: " << incorrectCounter << endl << endl;
}
}
|