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
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Constants
const int NUMBER_QUESTIONS = 20;
// Function prototypes
void readFile(ifstream&, char, int);
int compareAnswers(char, char, int);
void displayTestResults(int, int);
int main()
{
ifstream CorrectAnswers; // Input file stream object
ifstream StudentAnswers;
char cAnswer[NUMBER_QUESTIONS];
char sAnswer[NUMBER_QUESTIONS];
CorrectAnswers.open("CorrectAnswers.txt"); // Open CorrectAnswers.txt file.
StudentAnswers.open("StudentAnswers.txt");
readFile(CorrectAnswers, cAnswer, NUMBER_QUESTIONS);
readFile(StudentAnswers, sAnswer, NUMBER_QUESTIONS);
//I need other function calls here and I'm aware of that. Just trying to get readfile to work first.
return 0;
}
//*****************************************************************************
//This function reads data from a file
//*****************************************************************************
void readFile(ifstream &inFile, char answers[],int num)
{
for (int i = 0; i < num; i++)
{
inFile >> answers[i];
}
inFile.close();
return;
}
//*****************************************************************************
//This function compares students answers with the professors answer key
//*****************************************************************************
//Missed argument isn't needed for this function to operate properly you can return
//what's needed for calculations without it.
int compareAnswers(char cArray[], char sArray[], int num)
{
int missed = 0;
cout << setw(25) << "Missed Question" << setw(25) << "Students Answer" << setw(25) << "Correct Answer\n";
for (int i = 0; i < num; i++)
{
if (cArray[i] != sArray[i])
{
cout << setw(25) << "#" << i << setw(25) << sArray[i] <<setw(25) << cArray[i] << endl;
missed +=missed;
}
}
return missed;
}
//*****************************************************************************
//This function displays the test results
//*****************************************************************************
void displayTestResults(int num1, int num2)
{
int numCorrect = 0;
double percent;
percent = (double)num1 / num2 * 100; // double cast to insure floating point division
numCorrect = num2 - num1;
cout << "number of correct answers: " << numCorrect << endl;
cout << "\n";
cout << "Percentage answered correctly: " << setprecision(2) << showpoint << percent << "%\n";
cout << "\n";
if (percent >= 70.00)
cout << "The student passed the exam\n";
else
cout << "The student failed the exam\n";
return;
}
|