I have been asked to write a program to grade several multiple-choice exams. The exam has less than 80 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on several files such as exam1.dat where the first line is the key, consisting of a string of n characters (0<n < 80). The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of n characters.
The program should have a while loop in the main routine to ask users input a data file name through keyboard. In this way, the program has a capability of repeatedly asking for a new data file in each while loop until users input a key word “exit”. Once “exit” is encountered, the while loop terminates and your program ends. A typical input exam data file (exam1.dat) looks like:
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
Apply strlen( ) or the length( ) of string to the first line of the above data file for determining the number of questions in the problem. If a student gives more answers than necessary, the extra answers will be automatically truncated. On the other hand, if a student provides less number of answers, the remaining unanswered questions are considered as being answered wrongly.
After users input an exam data file, your program should ask users to input another grade-curving file name (e.g., gradeCurving.dat). 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.
A 90
B 80
C 70
D 60
E 50
The above information means that ‘A’ = 90 through 100; ‘B’=80 through 89; ‘C’=70 through 79; ‘D’ = 60 through 69; “E”=50 through 59; For the remaining grades, you can assign an ‘F’.
Furthermore, in each while loop in the main routine, your program should ask users to input an output file name such as score1.dat. The output file will store the scores for each student in a format: student ID number, a space, a percentile score, and a curved grade in ‘A’ though ‘E’. The program should also compute and display the following statistics for the graded answers: Average score, Maximum score, and Minimum score.
A typical output on a data file looks like:
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%
This Is what I have so far. It compiles fine and everything but when I input the files it says "There was an error opening the corresponding files. Check input name perhaps?" an it exits out so can anyone help. It would be appreciated. I'm going to keep working on it but I've been doing this for weeks.
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
int openfiles(ifstream& infile, ifstream& curvingfile, ofstream& outfile);
void Size(ofstream&,int,string);
int main()
{
int num_student = 4, count, length, score2, w[6];
ifstream infile, curvingfile; char x;
ofstream outfile; float score;
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;
}
string key, answer, id;
do {
openfiles(infile, curvingfile, outfile); // function calling
infile >> key; // answer key
for (int i = 0; i < num_student; i++) // loop over each student
{
infile >> id;
infile >> answer;
count = 0;
length = key.size();
Size (outfile, length, answer);
for(int j = 0; j < length; j++) // loop over each question
{
if (key[j] == answer[j])
count++;
}
score = (float) count / length;
score2 = (int)(score * 100);
outfile<< id <<" "<< score2 <<" % " ;
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;
}
cout << " New Trial? (y/n):";
cin >> x;
}
while (x == 'y' || x == 'Y');
return 0;
}
int openfiles(ifstream& infile, ifstream& curvingfile, ofstream& outfile)
{
string name1, name2, name3, answerstring, curvedata;
cin >> name1; name2; name3;
cout << "Input the name for the exam file: ";
cin >> name1;
infile.open(name1.c_str());
infile >> answerstring;
cout << "Input the name for the curving file: ";
cin >> name2;
infile.open(name2.c_str());
infile >> curvedata;
cout << "Input the name for the output: ";
cin >> name3;
outfile.open(name3.c_str());
return true;
}
void Size(ofstream& outfile, int length, string answer)
{
bool check;
if (answer.size() > length)
{
outfile << "Unnecessary extra answers";
}
else if (answer.size() < length)
{
outfile << "The remaining answers are incorrect";
}
else
{check = false;};
}
|