you\'ve been asked to write a program to grade a multiple-choiceexam. the exam h
ID: 3612735 • Letter: Y
Question
you've been asked to write a program to grade a multiple-choiceexam. the exam has 20 questions, each answered with a letter in therange of 'a' through 'f'. the data are stored on a file (exams.dat)where the first line is the key, consisting of a string of 20characters the remaining lines on the file are exam answers, andconsist of a student ID number, a space and a string of 20characters. the program should read the key, then read each examand output the ID number and score to file scores.dat. erroneousinput should result in an error message. For example, given thedata:
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
3332221 abcdefghijklmnopqrst
The program would output on scores.dat
1234567 20
9876543 15
5554446 Too few answers
4445556 Too many answers
333221 Invalid answers
Use functional decomposition to solve the problem and code thesolution using functions as appropriate. Be sure to use properformatting and appropriate comments in your code. The output shouldbe neatly formatted, an the error messages should beinformative.
please help. thank you inadvance. i need it by sunday. thanks.
Explanation / Answer
please rate - thanks #include #include #include using namespace std; void gradetest(ifstream&,ofstream&,string,int,int); void printgrade(int,int,int,ofstream&); int main() {string answer; int id,max=20; ifstream input; ofstream output; input.open("exams.dat"); //open file if(input.fail()) //is it ok? { coutid; } input.close(); output.close(); system("pause"); return 0; } void gradetest(ifstream& in,ofstream& out,string right,intid,int max) {int count=0,printcode=0,i=0,j; string ans; in>>ans; while(ans[i]!='') {if(i>=max) {printgrade(id,0,1,out); return; } if(ans[i]'f') {printgrade(id,0,2,out); return; } if(ans[i]==right[i]) count++; i++; } if(iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.