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

I need help with this hwassignment, but please do not give the same code as belo

ID: 3613110 • Letter: I

Question

I need help with this hwassignment, but please do not give the same code as below theproblem however you can follow it. I will not rate it if same codeis copied, any different code gets lifesaver. Code below isincorrect.
Thank You and help will be appreciated

3. You have been asked towrite a program to grade a multiple choice exam. The exam has 20questions each answered with a letter in the range of 'a' through'f'. The data are stored on a file [exam.dat] where the first lineis the key, consisting of a string of 20 characters. The remaininglines on the file are exam answers, and consist of a student IDnumber, a space and a string of 20 characters. The program shouldread the key, then read each exam and output the ID number andscore to file scores.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 proper formatting andappropriate comments in your code. The output should be neatlyformatted, and the error messages should be informative

CODE

#include<iostream>
#include <fstream>
#include <iomanip>
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?
    { cout<<"input file did not open pleasecheck it ";
     system("pause");
     return 1;
     }
output.open("scores.dat");          //open file
if(output.fail())            //is it ok?
    { cout<<"output file did not open pleasecheck it ";
     system("pause");
     return 2;
     }    
input>>answer;
output<<"   ID Grade ";
input>>id;
while(input)
   {gradetest(input,output,answer,id,max);
    input>>id;
   }
input.close();
output.close();
system("pause");
return 0;
}

voidgradetest(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]<'a'||ans[i]>'f')
       {printgrade(id,0,2,out);
         return;
        }    
     if(ans[i]==right[i])
          count++;
     i++;
     }
if(i<max)
     printgrade(id,0,3,out);
else
     printgrade(id,count,0,out);
return;
}
void printgrade(int id, int count,int code,ofstream& out)
    {out<<id<<" ";
     if(code==0)
        out<<count<<endl;
     else if(code==1)
         out<<"Toomany answers ";
     else if(code==2)
         out<<"Invalid answer(s) ";
     else
         out<<"Too few answers ";
     return;
    }      

Explanation / Answer

#include #include #include using namespace std;int wrong(char *p2){int i;for(i=0;i'f'){return 0;} return 1;}void corr(char *p2){char *p="abcdefabcdefabcedfab";int count=0;int i;for(i=0;i