hello
we have to make a program that grades multiple choice exams from input files by the user and outputs the id of each student followed by their appropriate score.
here are the input files:
exam file
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
where the first line is the answer key, and the first column of numbers is 4 student ids, followed by the second column of their answers. in this case, the program compares the answers with the answer key and outputs the scores to each of the ids on the output file.
curve file
A 90
B 80
C 70
D 60
E 50
i didnt know how to implement this exactly. the professor showed us to make the if statements as seen in my code about if <=90 for say, "A". and so on. this is what the rubric says : "This second file contains the information to convert a percentile score to a curved grade in levels of ‘A’ through ‘E’. For instance, a grade-curving file takes the following format: a curved alphabetic grade, a space, a percentile grade served as marker."
output file example
1234567 90% A
9876543 85% B
5554446 95% A
4445556 75% C
5551112 80% B
Statistics:
Average Score: 85%
Minimum Score: 95%
Maximum Score: 75%
and here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int openFiles(ifstream& inFile, ifstream& curvingFile, ofstream& outFile);
void size(ofstream& outFile, int keylength, string answers, string key, string id);
int main()
{
ifstream inFile, curvingFile;
ofstream outFile;
int num_student = 4;
string key, id, answers, w[6];
int keylength;
char x;
int open = openFiles(inFile, curvingFile, outFile);
if (open != 3)
{
cout << "There was an error opening the corresponding files. Check input name perhaps?" << endl;
return 0;
}
//program initiates here...
/*while (inFile >> id[0] >> answers)
{
outFile << id << " ";
size(outFile, keylength, answers, key);
}*/// this is a temporary old code. keeping it in case....
do {
openFiles(inFile, curvingFile, outFile); // function calling
inFile >> key; // answer key
keylength = key.length();// length represents number of questions in exam from exam1.dat
inFile >> id[0];
inFile >> answers;
for (int i = 0; i < num_student; i++) // loop over each student
{
size(outFile, keylength, answers, key, id);
}
cout << "Would you like to attempt a new trial? (y/n): ";
cin >> x;
} while (x == 'y' || x == 'Y');
system("pause");
return 0;
}
int openFiles(ifstream& inFile, ifstream& curvingFile, ofstream& outFile)
{
string inFileName, curvingFileName, outFileName;
cout << "Input the name of the input file: " << endl;
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << "Input the name of the curving file: " << endl;
cin >> curvingFileName;
curvingFile.open(curvingFileName.c_str());
cout << "Input the name of the output file: " << endl;
cin >> outFileName;
outFile.open(outFileName.c_str());
//outFile << "These are the student scores for " << inFileName << endl; // this is a general statement that identifies what the scores are for...the name if inFile name that is
//outFile << fixed;
return true;
}
void size(ofstream& outFile, int keylength, string answers, string key, string id)
{
int length, grade = 0, score2;
float score;
bool check;
if (answers.length() < keylength)
{
outFile << "the unanswered questions were counted as incorrect answers";
}
/*else if (answers.length() > keylength)
{
outFile << "Unnecessary extra answers"; // how do i automatically make it truncate?
}*/
else
{
check = false;
}
for (int count = 0; count < key.length(); count++)
{
if (answers[count] == key[count])
{
grade++;
}
score = (float)grade / keylength;
score2 = (int)(score * 100);
/*else if (answers[count] != 'a' && answers[count] != 'b' && answers[count] != 'c' && answers[count] != 'd' && answers[count] != 'e' && answers[count] != 'f')
{
check = true;
}
if (check == true)
{
outFile << "Invalid Answer";
}*/ // this long comment states that if the student has some different answer like g or h that is not even something in the answer key, check = true.
outFile << id << " " << score2 << "%"; // else needed here with brackets that include the outfile << grade; (original one instead of outFile << id <<....) if activate above comments
if (score2 >= 90)//<-----w[0]
outFile << "A" << endl;
else if (score2 >= 80)//<-----w[1]
outFile << "B" << endl;
else if (score2 >= 70)//<-----w[2]
outFile << "C" << endl;
else if (score2 >= 60)//<-----w[3]
outFile << "D" << endl;
else if (score2 >= 50)//<-----w[4]
outFile << "E" << endl;
else if (score2 < 50)//<-----w[5]
outFile << "F" << endl;
}
outFile << endl;
}
i worked really hard on this, spending about 30 hours over the last days and week. as a beginner, i managed to do this much (85%) and i am facing the problems of "Cannot find or open the PDB file."
am i supposed to place the files in a special place for the program to read it? i dont know what is going on, cause its not identifying the files even though i tried many ways of renaming back in the project directory the input files and inputting that name into the console questions, yet it terminates with that statement.
also, how do i make a statistics category to output to the outfile? i dont know how to make maximum score, minimum score, and average score. i have the idea of
int max = score2
int min = score2
float average
if (score2> "i wanna say here than all other scores, but dont know how")
outFile << "maximum score is " << max <<endl;
if (score2< all other scores)
outFile << "minimum score is " << min << endl;
average=(score2+score2+score2+score2)/4
outFile << "the average score is" << average << endl;
//i am sure this is incorrect and missing, but thats what i had in mind
thnx anyone in advance!