Hello
Can you guys check the code plz thanks);
the q
Project description
Write a program to grade an n -question multiple-choice exam (for n between 5 and 50)
and provide a feedback report about the exam.
Your program will take data from the user or a file, depending on the user’s choice.
If the user chooses to input the data manually, then the input line contains the exam’s number of questions (n) followed by a space and then an n-characters string of the correct answers.
Then each input contains a long integer student ID followed by a space and then that student’s answers.
If the user chooses to input the data from a file, then the first line in the file should contain an integer representing the number of exam sheets (students), followed by another line that contains the number of questions (n), followed by a sequence of n-characters, which represents the correct answers.
Then the following lines represent each student’s response and begin with the student ID, followed by the answers.
Your program is to produce an output file containing the answer key, each student’s ID and each student’s score as a percentage and then information about how many students missed each question, class average and student percentage with grade letter.
end of q
START: CODING in c++
#include
#include<stdio.h>
using namespace std;
void fgetAnswers(char answers, int n, FILE*inp) // function declaration
int main()
{
FILE *inp = fopen(“examdat.txt”, “r”); // defining file input
int n,i;
char answers[20], ch;
fscan (inp, "%d", &n); // scanning from the file the number of answers
fscan(inp, "%c",&ch);
for (i=0;i<n;i++)
{
fscanf(inp, "%c", &answers[i]); // scanning the answers
}
fgetAnswers (answers, n, inp); // calling the function
return 0;
}
void fgetAnswers (char answers[], int n, FILE*inp)
{
FILE *outp = fopen("report.txt", "w"); // defining the file output
int missed [20], i; // declaring the variables, the new array for the missed qs
int id, correct;
char choice;
fprintf(outp, "Exam Report\n\n"); //printing in the file
fprintf (outp, "Question\t");
for (i=0; i<n; i++)
{
fprintf(outp,"%d" ,i); // print the qs numbers
}
fprintf(outp, "\nAnswer\t\t")
for (i=0;i<n;i++)
{
fprint (outp, "%c ", answers[i]); // printing the correct answers
}
for (i=0; i<20; i++)
{
missed[i] = 0; // intializing all missed qs to 0
}
fprintf (outp, "\n\n ID \t Score(%%) \n"); // starting hte student wise report
while (fscanf(inp, "%d", &ID) ! = EOF) // scanning the ID if end of file not occured, the loop continues
{
correct=0;
fprintf (outp,"%d\t", id); // printing ID
fscanf(inp, "%c", &choice);
for (i=0; i<n; i++)
{
fscanf(inp, "%c", &choice); //scanning the choice
if (choice== answers[i]) // checking if correct choice
{
fprintf (outp, "%d", missed[i]); // corresponding missed nums
}
fprintf (outp, "\n\n");
}
}
}
}
}
}
}