Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program will grade a series of exams and then print a grade report for stude

ID: 3815598 • Letter: T

Question

The program will grade a series of exams and then print a grade report for students in a course. Input: An instructor has a class of students each of whom takes a multiple-choice exam with 10 questions. For each student in the class, there is one line in the input file. The line contains the answers that student gave for the exam. The input file named "grade_data.txt" will have the following format: line 1: the key for the exam (e.g.) bccbbadbca lines 2-n: bccbbbdbbb bccbbadbca bccbbadbbb etc. a set of answers. You know you are done when you get to a line with no data. Processing: The program is to read the input file and grade each exam and print out the score for that exam. You will also keep track of how many students earned each score (0-10) and print a report after the grading. Output: Here is an example of how the output might appear. You will write the report to an output file named "grade_report.txt" student 1 - 8 student 2 - 10 student 3 - 1 etc. Final Report 10 - 4 9 - 2 8 - 3.. 1 - 3 0 - 0

Explanation / Answer

//C++ Program:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

bool readSolution(char[],ifstream&);
int determineGrade(char[],char[]);
void printStudentsInfo(int,int,ofstream&);
void readStudentScores(int,int&,int&,int[]);
void printResults(int,int[],int,int,int,ofstream&);

int main()
{
int total=0,Lowest=50,high=0,Studentscores[11]={0},count=0,correctAnswers;
char answers[10],student[10];
ifstream inFile;
ofstream outFile;
inFile.open("grade_data.txt");
if(inFile.fail())
{ cout<<"input file did not open please check it ";
return 1;
}
outFile.open("grade_report.txt");
readSolution(answers,inFile);
while(readSolution(student,inFile))
{
count++;
correctAnswers=determineGrade(answers,student);
total+=correctAnswers;
printStudentsInfo(count,correctAnswers,outFile);
readStudentScores(correctAnswers,Lowest,high,Studentscores);
}
printResults(total,Studentscores,Lowest,high,count,outFile);
outFile.close();
inFile.close();
return 0;
}
bool readSolution(char s[],ifstream& inFile)
{int i;
inFile>>s[0];
if(!inFile)
return false;
for(i=1;i<10;i++)
inFile>>s[i];
return true;
}
int determineGrade(char a[],char s[])
{int i,tot=0;
for(i=0;i<10;i++)
if(s[i]==a[i])
tot++;
return tot;
}
void printStudentsInfo(int i,int s,ofstream& out)
{out<<"student "<<i<<" - "<<s<<endl;
}
void readStudentScores(int correctAnswers,int& Lowest,int& high,int Studentscores[])
{if(correctAnswers<Lowest)
Lowest=correctAnswers;
if(correctAnswers>high)
high=correctAnswers;
Studentscores[correctAnswers]++;
}


void printResults(int total,int Studentscores[],int l,int h,int c,ofstream& out)
{
int i;
out<<" Final Report ------------- ";
for(i=10;i>=0;i--)
out<<i<<" - "<<Studentscores[i]<<endl;
}


/*
grade_data.txt
bccbbadbca
abcdabcdab
bcdababcda
bccbbadbca
abcdabcdab
adbcabccbb
abcdaadbca
adbcaabcda
abcdabcdab
bcdabadbca


grade_report.txt
student 1 - 1
student 2 - 5
student 3 - 10
student 4 - 1
student 5 - 0
student 6 - 6
student 7 - 2
student 8 - 1
student 9 - 8


Final Report
-------------
10 - 1
9 - 0
8 - 1
7 - 0
6 - 1
5 - 1
4 - 0
3 - 0
2 - 1
1 - 3
0 - 1

*/