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 85 86 87 88 89 90 91 92 93 94
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void studentsTest(string fileName, char student_answers[], int response, int QUESTION_AMT);
void checkAnswers(char answers[], char student_answers[], int QUESTION_AMT, int MIN_CORRECT);
int main()
{
int response;
const int QUESTION_AMT = 20;
const int MIN_CORRECT = 15;
char answers[QUESTION_AMT] = { 'A', 'D', 'B', 'B', 'C', 'B', 'A', 'B', 'C', 'D', 'A', 'C', 'D', 'B', 'D', 'C', 'C', 'A', 'D', 'B' };
char student_answers[QUESTION_AMT];
string fileName;
ofstream textOut;
studentsTest(fileName, student_answers, response, QUESTION_AMT); /*I keep getting error C4700: uninitialized local variable 'responce' used*/
checkAnswers( answers, student_answers, QUESTION_AMT, MIN_CORRECT);
cout << endl << endl;
system("pause");
return (0);
}
void studentsTest(string fileName, char student_answers[], int response, int QUESTION_AMT)
{
cout << "\nPlease enter a name for your file>";
getline(cin, fileName);
ofstream textOut;
textOut.open(fileName);
for (int response = 0; response < QUESTION_AMT; response++)
{
cout << "Please enter your answers: " << (response + 1) << ": ";
cin >> student_answers[response];
while (student_answers[response] != 'A' && student_answers[response] != 'B' && student_answers[response] != 'C' && student_answers[response] != 'D')
{
cout << "\nError! Answers must be in captial letters! ex: A, B, C";
cout << "Please enter your answers: " << (response + 1) << ": ";
cin >> student_answers[response];
}
}
ifstream textIn;
textIn.open(fileName);
if (textIn.fail())
{
cout << "\nText file not found...program will close";
cout << endl << endl;
system("pause");
}
textIn.close();
}
void checkAnswers(char answers[], char student_answers[], int QUESTION_AMT, int MIN_CORRECT)
{
int correctAnswers = 0;
for (int i = 0; i < QUESTION_AMT; i++)
{
if (answers[i] == student_answers[i])
correctAnswers++;
}
cout << "\nStudent must have at least 15 correct answers to pass.";
if (correctAnswers >= MIN_CORRECT)
{
cout << "\nYou passed the exam!";
}
else
{
cout << "\nYou failed the exam!";
}
cout << "\nThe following is the list of questions that are incorrect";
for (int i = 0; i < QUESTION_AMT; i++)
{
if (answers[i] != student_answers[i])
cout << "Question # " << i << " is incorrect! " << endl;
}
cout << "\nCorrect Answers = " << correctAnswers << endl;
cout << "\nIncorrect Answers = " << QUESTION_AMT - correctAnswers << endl;
}
|