I have looked around the website using the search and have seen old post so I am posting a new question most likely to an old answer. I am trying to read data from a file into an array and then pass it on to a function. I also have another file that I am trying to read into an array and pass it to a function. I don't have this program completed and I am looking for some guidance to finish it.
The Assignment is as follows:
One of your professors has asked you to write a program to grade her final exams, which consist of only 20 multiple choice questions. Each question has one of four possible answers: A,B,C, or D. The file CorrectAnswers.txt, which is on the student CD, contains the correct answers for all of the questions, each answer written on a separate line. The first line contains the answer to the first question, the second line contains the answer to the second questions and so forth.
Write a program that reads the contents of the CorrectAnswers.txt file into a one-demensional char array, and then reads the contents of another file, containing the students asnwers, into a second char array. The student CD has a file named StudentAnswers.txt that you can use for testing purposes. The program should determine the number of questions that the student missed, and then display the following:
A: A list of questions missed by the student, showing the correct answer and the incorrect answer provided by the student for each missed question.
B: The total number of questions missed.
C: The percentage of questions answered correctly. ( Correctly answered questions divided by total number of questions)
D: If the percentage of correctly answered questions is 70% or great, the program should indicate that the student has passed the exam. Otherwise, it should state the student has failed the exam.
//This program grades student scores. This program will calculate the score and show the grade percentage.
//Show a list of questions missed, show the incorrect answer and the correct answer.
//The total number of questions missed.
//The program will state if the student passed (grade above 70%) or if they did not.
//Programming Challange 7.12
#include <iostream>
#include <fstream>
using namespace std;
// Function prototypes
void getCorrectAnswers(char[], int); // Used to read the correct answers key
void getStudentAnswers(char[], int); // used to read the student answers
void compareAnswers(char[], int); // used to compare the answers and then display the missed quetions with the correct questions
void testGrade(float[] ,int); // used to grade the test based on the compared questions, 70% or greater to pass
int main()
{
cout << "This program will read the correct test answers and the student answers.\n";
cout << "First we will read the correct answers into the program...\n";
getCorrectAnswers;
cout << "Now reading the student answers file...\n";
getStudentAnswers;
cout << "Going to now show the missed questions with the correct answers.\n";
compareAnswers;
testGrade;
system ("pause");
return 0;
}
// This function reads the correct answers key.
void getCorrectAnswers(char[], int)
{
const int ARRAY_SIZE = 20; // Array size
int correctAnswers[ARRAY_SIZE]; // Array with 20 correct answers
int count; // Loop counter variable
ifstream inputFile; // Input file stream object
inputFile.open("C:\\Users\\sixcore\\Documents\\Visual Studio 2010\\Projects\\exam_grader\\CorrectAnswers.txt"); // Correct answers
// Read the 20 correct answers from the file into the array.
for (count = 0; count < ARRAY_SIZE; count++)
inputFile >> correctAnswers[count];
// Close the file.
inputFile.close();
return correctAnswers;
}
//This function reads the student Answers.
void getStudentAnswers(char[], int)
{
// This array reads the student answers to the array
const int ARRAY_SIZE = 20; // Array Size
int studentAnswers[ARRAY_SIZE]; // Array with 20 student answers
int count; //Loop counter variable
ifstream inputFile;
inputFile.open ("C:\\Users\\sixcore\\Documents\\Visual Studio 2010\\Projects\\exam_grader\\StudentAnswers.txt"); // Student answers
// Read the 20 student answers
for (count = 0; count < ARRAY_SIZE; count++)
inputFile >> studentAnswers[count];
// Close the file.
inputFile.close();
return studentAnswers;
}
// This function compares the Correct Answers key to the student answers.
void compareQuestions(char[], int)
{
const char SIZE = 1;
char correctAnswers;
char studentAnswers;
char compareAnswers;
bool arraysEqual = true;
int count = 0;
//Compare the student answers to the correct answers.
while (arraysEqual && count < SIZE)
{
if (correctAnswers[count] != studentAnswers[count])
arraysEqual = false;
count ++;
}
if (arraysEqual)
cout << "The Correct Answers compared to the student answers.\n" << compareAnswers << endl;
else
return;
}
//This function grades the test answers
// Having troule here with how to finish
void testGrade(float[], int)
{
int grade;
cout << "Going to now show the grade if it is higher than 70%.\n";
if (grade >= 70)
cout << "The student has passed.\n";
else
cout <<" The student did not pass.\n";
}