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
|
#include <iostream>
#include <string>
#include <array>
#include <fstream>
using namespace std;
void getanswers(ifstream& testscore, char answers[]);
void getstudentanswers(ifstream& testscore, char studentid[][9], char studentanswers[][21]);
void printanswers(char studentid[][9], char studentanswers[][21], int studentscore[]);
void comparescores(char answers[], char studentanswers[][21], int studentscore[]);
int main()
{
char answers[20]; //correct answers used to calculate score.
char studentid[150][9]; //
char studentanswers[150][21];
int studentgrades[150] = {0};
ifstream testscore;
ofstream outfile;
testscore.open("testscores.txt");
outfile.open("output.txt");
getanswers(testscore, answers);
for (int i = 0; i < 20; i++)
{
cout << answers[i];
}
cout << endl;
testscore.ignore(256, '\n');
getstudentanswers(testscore, studentid, studentanswers);
comparescores(answers, studentanswers, studentgrades);
printanswers(studentid, studentanswers, studentgrades);
testscore.close();
outfile.close();
system("PAUSE");
return 0;
}
void getanswers(ifstream& testscore, char answers[])
{
for (int i = 0; i < 20; i++)
{
testscore.get(answers[i]);
}
}
void getstudentanswers(ifstream& testscore, char studentid[][9], char studentanswers[][21])
{
int i = 0;
while(testscore)
{
testscore.get(studentid[i], 9, ' ');
testscore.ignore(256, ' ');
testscore.get(studentanswers[i], 21, '\n');
testscore.ignore(256, '\n');
i++;
}
}
void printanswers(char studentid[][9], char studentanswers[][21], int studentscore[])
{
for (int i = 0; i < 2; i++)
{
cout << studentid[i] << " " << studentanswers[i] << " " << studentscore[i] <<endl;
}
}
void comparescores(char answers[], char studentanswers[][21], int studentscore[])
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 20; j++)
{
if (studentanswers[i][j] == answers[j])
{
studentscore[i] += 2;
}
else if (studentanswers[i][j] != answers[j])
{
studentscore[i] -= 1;
}
else if (studentanswers[i][j] == ' ')
{
studentscore[i] = studentscore[i];
}
}
}
}
|