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
|
#include <iostream>
#include <iomanip>
#include <cctype>
using namespace std;
void checkAnswers(char[], char[], int, int);
int main()
{
char characters[4] = { 'A', 'B', 'C', 'D' };
char user_input = 'a';
user_input = ::toupper(user_input); //Convert to upper-case. If the argument is already upper-case, it does nothing.
const int NUM_QUESTIONS = 20;
const int MIN_CORRECT = 15;
char stu_answers[NUM_QUESTIONS] = {};
char answers[NUM_QUESTIONS] = {
'A', 'D', 'B', 'B', 'C',
'B', 'A', 'B', 'C', 'D',
'A', 'C', 'D', 'B', 'D',
'C', 'C', 'A', 'D', 'B',
};
cout << "Welcome to the Driver's License Office" << endl;
cout << "Only valid answers will be A, B, C, or D" << endl;
int i = 0;
for (i = 0; i < NUM_QUESTIONS; i++){ //loop for answers
cout << "Please enter your answers: " << (i + 1) << ":";
cin >> stu_answers[i];
}
while (stu_answers[i] != 'A' && stu_answers[i] != 'B' && stu_answers[i] != 'C' && stu_answers[i] != 'D') {
cout << "You must enter A, B, C, or D\n";
cout << "Please enter your answers: "
<< (i + 1) << ": ";
cin >> stu_answers[i];
}
}
void checkAnswers(char answers1[], char stu_answers1[], int NUM_QUESTIONS, int MIN_CORRECT) {
//cout << "max: " << NUM_QUESTIONS;
int correctAnswers = 0;
//Check the student's replies against the correct answers
for (int i = 0; i < NUM_QUESTIONS; i++) {
if (answers1[i] == stu_answers1[i])
correctAnswers++;
}
//Did they pass or fail?
cout << "\nYou must have at least 15 correct to pass.";
if (correctAnswers >= MIN_CORRECT) {
cout << "\nStudent passed the exam\n\n";
}
else {
cout << "\nStudent failed the exam\n\n";
}
//Display a list of the questions that were incorrectly answered.
cout << "The list below shows the question numbers of the incorrectly";
cout << " answered questions.\n";
for (int i = 0; i < NUM_QUESTIONS; i++) {
if (answers1[i] != stu_answers1[i])
cout << "Question # " << i << " is incorrect." << endl;
}
//Display the number of correct and incorrect answers provided by the student.
cout << "\nCorrect Answers = " << correctAnswers << endl;
cout << "Incorrect Answers = " << NUM_QUESTIONS - correctAnswers << endl;
}
|