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
|
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void pause();
bool studentResults(char, char, bool, const int);
int main()
{
const int ANS = 20;
char answers[ANS] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D',
'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'},
sAnswer[ANS];
bool pass;
cout << "This program will ask for the student's answer to\n"
<< "his driving test. And will tell you whether he passed\n"
<< "or not.\n";
for (int count = 0; count < ANS; count ++)
{
cout << "\nAnswer for question n° " << count + 1 << "?";
cin >> sAnswer[count];
if (sAnswer[count] != 'A' && sAnswer[count] != 'B' &&
sAnswer[count] != 'C' && sAnswer[count] != 'D')
{
cout << "\nThe answer can only be A, B, C, or D!\n"
<< "\nAnswer for question n° " << count + 1 << "?";
cin >> sAnswer[count];
}
}
pass = studentResults (answers, sAnswer, pass, ANS);
if (pass)
cout << "\n\nCongratulations! You passed your driving test!";
else
cout << "\n\nSorry, you didn't pass your driving test.";
pause();
}
bool studentResults( char answers[], char sAnswer[], bool pass, const int ANS)
{
int goodAnswers = 0,
badAnswers;
cout << "\n\n\t\tTEST RESULTS\n";
for (int count = 0; count < ANS; count ++)
{
cout << "\nQuestion " << count + 1 << ", good answer: "
<< answers[count]
<< "----- Your answer: " << sAnswer[count] << " _____ ";
if( answers[count] == sAnswer[count])
{
cout << "V";
goodAnswers += 1;
}
else
cout << "X";
}
badAnswers = ANS - goodAnswers;
if (goodAnswers >= 15)
pass = true;
return(pass);
}
void pause()
{
printf("\n%S", "Press any key to continue");
_getch();
printf("\n\n");
return;
}
|