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
|
#include <iostream>
using namespace std;
void input(char [], int);
void checkAnswers (char answers[], char stuInput[], int& questions, int& minCorrect);
int main()
{
int questions = 20;
int minCorrect = 15;
char answers [20] = {'A','D','B','B','C','B',
'A','B','C','D','A','C',
'D','B','D','C','C','A','D','B'};
char stuInput [questions];
input (stuInput, questions);
checkAnswers (answers, stuInput, questions, minCorrect);
return 0;
}
void input(char stuInput[], int questions)
{
cout << "Please enter the student's answers for each question." << endl;
cout << "Please Enter after typing each answer." << endl;
cout << "Please enter only an A, B, C, D, or a, b, c, d, for each question." << endl;
// Loop for users answers
for (int answ = 0; answ < questions; answ++) {
cout << "Question " << (answ+1) << ": ";
cin >> stuInput[answ];
// Validation for user answers
while (stuInput[answ] != 'A' && stuInput[answ] != 'B' &&
stuInput[answ] != 'C' && stuInput[answ] != 'D' &&
stuInput[answ] != 'a' && stuInput[answ] != 'b' &&
stuInput[answ] != 'c' && stuInput[answ] != 'd')
{
cout << "Use only A, B, C, D or a, b, c, d!\n";
cout << "Please try again." << endl;
cout << "Question " << (answ+1) << ": ";
cin >> stuInput[answ];
}
}
}
void checkAnswers (char answers[], char stuInput[], int& questions, int& minCorrect)
{
int correctAnswers = 0;
//Check the student's replies against the correct answers
for (int i = 0; i < questions; i++)
{
if (answers[i] == stuInput[i])
correctAnswers++;
}
//Pass or fail?
if (correctAnswers >= minCorrect)
{
cout << "\nThe student passed the exam.\n";
}
else
{
cout << "\nThe student failed the exam.\n";
}
//Display list of questions incorrectly answered
cout << "\nQuestions that were answered incorrectly:\n";
for (int i = 0; i < questions; i++)
{
if (answers[i] != stuInput[i])
cout << i << endl;
}
//Display the number of correct and incorrect answers
cout << "\nCorrect answers: " << correctAnswers << endl;
cout << "\nIncorrect answers: " << questions - correctAnswers << endl;
}
| |