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
|
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void single_grade(string key, string first[], string last[], string answer[], double grade[]);
void output(string key, string first[], string last[], string answer[]);
int main(){
string input_filename, first[9], last[9], answer[9], key;
double grade[10];
cout << "Enter the name of the file where the ungraded tests are located: ";
cin >> input_filename;
ifstream inp;
inp.open(input_filename.c_str());
getline(inp, key);
for(int i=0; !inp.eof(); i++){
getline(inp, first[i], ' ');
getline(inp, last[i], ' ');
getline(inp, answer[i]);
}
inp.close();
output(key, first, last, answer);
single_grade(key, first, last, answer, grade);
return EXIT_SUCCESS;
}
void single_grade(string key, string first[], string last[], string answer[], double grade[]){
double score;
double ppts;
for(int j = 0; j < 9; j++){
score = 0;
ppts = 0;
for(int i = 0; i < answer[j].size(); i++){
if(answer[j].at(i) == key.at(i)){
++score;
}
++ppts;
}
grade[j] = (score/ppts)*100;
}
}
void output(string key, string first[], string last[], string answer[]){
for(int i = 0; i < 15; i++){
cout << answer[i].at(i) << "(" << key.at(i) << ")" << endl;
}
}
|