3. You have been asked to write a program to grade a multilechoice exam. The exa
ID: 3612968 • Letter: 3
Question
3. You have been asked to write a program to grade a multilechoice exam. The exam has 20 questions each answered with a letterin the range of 'a' through 'f'. The data are stored on a file[exam.dat] where the first line is thekey, consisting of a string of 20 characters. The remaining lineson the file are exam answers, and consist of a student ID number, aspace and a stirng of 20 characters. The program should read thekey, then read each exam and ouput the ID number and score to filescores.dat.Erroneous input should result in an errormessage. For example, given the data abcdefabcdefabcdefab 1234567 abcdefabcdefabcdefab 9876543 abddefbbbdefcbcdefac 5554446 abcdefabcdefabcdef 4445556 abcdefabcdefabcdefabcd 3332221 abcdefghujklmnopqrst The program would output on scores.dat: 1234567 20 9876543 15 5554446 Too few answers 4445556 Too many answers 3332221 Invalid answers Use functional to solve the probem and code the solution usingfunctions as appropriate. be sure to use proer formatiing andappropriate comments in your code. The output should be neatlyformatted, and the error messges should be informative. 3. You have been asked to write a program to grade a multilechoice exam. The exam has 20 questions each answered with a letterin the range of 'a' through 'f'. The data are stored on a file[exam.dat] where the first line is thekey, consisting of a string of 20 characters. The remaining lineson the file are exam answers, and consist of a student ID number, aspace and a stirng of 20 characters. The program should read thekey, then read each exam and ouput the ID number and score to filescores.dat.Erroneous input should result in an errormessage. For example, given the data abcdefabcdefabcdefab 1234567 abcdefabcdefabcdefab 9876543 abddefbbbdefcbcdefac 5554446 abcdefabcdefabcdef 4445556 abcdefabcdefabcdefabcd 3332221 abcdefghujklmnopqrst The program would output on scores.dat: 1234567 20 9876543 15 5554446 Too few answers 4445556 Too many answers 3332221 Invalid answers Use functional to solve the probem and code the solution usingfunctions as appropriate. be sure to use proer formatiing andappropriate comments in your code. The output should be neatlyformatted, and the error messges should be informative. For example, given the data abcdefabcdefabcdefab 1234567 abcdefabcdefabcdefab 9876543 abddefbbbdefcbcdefac 5554446 abcdefabcdefabcdef 4445556 abcdefabcdefabcdefabcd 3332221 abcdefghujklmnopqrst The program would output on scores.dat: 1234567 20 9876543 15 5554446 Too few answers 4445556 Too many answers 3332221 Invalid answers Use functional to solve the probem and code the solution usingfunctions as appropriate. be sure to use proer formatiing andappropriate comments in your code. The output should be neatlyformatted, and the error messges should be informative. 9876543 15 5554446 Too few answers 4445556 Too many answers 3332221 Invalid answers Use functional to solve the probem and code the solution usingfunctions as appropriate. be sure to use proer formatiing andappropriate comments in your code. The output should be neatlyformatted, and the error messges should be informative.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
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.