Hello cplusplus community!
I'm currently working on this program for class and i think i have it all figured out except I keep on getting this linker error: error LNK2019. I searched throughout the forums, google and have seen similar problems but they are all particular to the program being compiled. Here is the source code for my program, also I am using visual studios 2010 as my compiler.
// This program serves as an exam grader.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int SIZE = 25; //Size for arrays
const int LOCATION = 100; //Size for arrays
//main function
int main()
{
ifstream AnswerInput; //prepares file for reading
ifstream StudentInput; //prepares file for reading
ofstream OutputFile; //prepares file for reading
char AnswerFile[LOCATION]; //stores location of answer key
char StudentFile[LOCATION]; //stores location of student's answers
char OutputDestination[LOCATION]; // stores path of output file
char AnswerKey[SIZE]; // saves answer key to an array
char StudentData[SIZE]; // saves student's answer to an array
char FirstName[SIZE]; // saves student's first name to an array
char LastName[SIZE]; // saves student's last name to an array
char ID[SIZE]; // saves student's ID # to an array
bool Missed[SIZE]; // saves student's missed answers to an array
int totalwrong = 0;
cout << "****** EXAM GRADER ******\n";
openAnswerKeyFile(AnswerInput, AnswerFile[LOCATION]);//calls function
openStudentFile(StudentInput, StudentFile[LOCATION]);//calls function
openOutputFile(OutputFile, OutputDestination[LOCATION]);//calls function
readAnswerKey(AnswerInput, AnswerKey[SIZE]);//calls function
readStudentFile(StudentInput, StudentData[SIZE], FirstName[SIZE], LastName[SIZE], ID[SIZE]);//calls function
checkExam( Missed[SIZE], StudentData[SIZE], AnswerKey[SIZE]);//calls function
writeResults(OutputFile, Missed[SIZE], ID[SIZE], LastName[SIZE], FirstName[SIZE], totalwrong);//calls function
writeMissedQuestionsList(OutputFile, Missed[SIZE], StudentData[SIZE], AnswerKey[SIZE]);//calls function
computeLetterGrade(totalwrong);//calls function
system ("pause");
return 0;
}
//prepares file for reading
void openAnswerKeyFile(ifstream Answer1, char answerlocation[])
{
cout << "Please enter the location of the Answer Key File.\n";
cin >> answerlocation;
Answer1.open(answerlocation);
if (!Answer1)
{
cout << "Error opening file.\n";
system ("pause");
exit(0);
}
}
//prepares file for reading
void openStudentFile(ifstream Answer2, char studentlocation1[])
{
cout << "Please enter the location of the Student File.\n";
cin >> studentlocation1;
Answer2.open(studentlocation1);
if (!studentlocation1)
{
cout << "Error opening file.\n";
system ("pause");
exit(0);
}
return;
}
//prepares file for reading
void openOutputFile(ofstream output, char destination[])
{
cout << "Please enter the destination of the results.\n";
cin >> destination;
output.open(destination);
return;
}
//reads files information
void readAnswerKey(ifstream Answer, char answeraray1[])
{
for (int i = 0 ; i < SIZE; i++)
{
Answer >> answeraray1[i];
}
Answer.close();
}
//reads files information
void readStudentFile(ifstream student1, char stuAnswer1[], char first1[], char last1[], char id1[])
{
student1 >> id1;
student1 >> first1;
student1 >> last1;
for (int i = 0 ; i < SIZE; i++)
{
student1 >> stuAnswer1[i];
}
student1.close();
return;
}
//compares student's answers to the answer key
void checkExam(bool missed2[], char stuanswer2[], char answerKey2[])
{
for (int i = 0 ; i < SIZE; i++)
{
missed2[i] = false;
if (stuanswer2[i] != answerKey2[i])
{
missed2[i] = true;
}
}
return;
}
//writes the results to a text file
void writeResults(ofstream destination3, bool missed3[], char id3[], char last3[], char first3[],int &wrong3)
{
for (int i = 0 ; i < SIZE; i++)
{
wrong3 += missed3[i];
}
destination3 << " *** RESULTS ****\n";
destination3 << "__________________________________\n";
destination3 << "ID #: " << id3 << endl;
destination3 << "Name: " << last3 << ", " << first3 << endl;
destination3 << "Stundents Answer--Correct Answer\n\n";
return;
}
//writes the results to a text file
void writeMissedQuestionsList(ofstream destination4, bool missed4[], char stuAnswer4[], char answerKey4[])
{
for (int i = 1 ; i <= SIZE; i++)
{
if (missed4[i] == 1)
{
destination4 << " " << setw (4) << i << ". " << stuAnswer4[i] << "----------" << answerKey4[i] << endl;
}
}
destination4.close();
return;
}
//writes the results to a text file
void computeLetterGrade(int wrong5)
{
int percentage = 0;
int totalquestions = 25;
percentage = ((totalquestions - wrong5)/totalquestions) * 100;
cout << "\nYour letter grade is: ";
if (percentage <= 100 || percentage >= 90)
cout << "A\n";
else if (percentage < 90 || percentage >= 80)
cout << "B\n";
else if (percentage < 80 || percentage >= 70)
cout << "C\n";
else if (percentage < 70 || percentage >= 60)
cout << "D\n";
else if (percentage < 60)
cout << "F\n";