Answered step by step
Verified Expert Solution
Question
1 Approved Answer
My code isn't opening the files that I have attached. What do I have wrong? #include #include #include #include using namespace std; const int NUM
My code isn't opening the files that I have attached. What do I have wrong?
#include
#include
#include
#include
using namespace std;
const int NUMQUESTIONS ;
int main
char correctAnswersNUMQUESTIONS;
char studentAnswersNUMQUESTIONS;
Read correct answers from CorrectAnswers.txt
fstream correctFileCorrectAnswerstxt;
if correctFile
cerr "Error opening CorrectAnswers.txt
;
return ;
for int i ; i NUMQUESTIONS; i
if correctFile correctAnswersi
cerr "Error reading correct answers
;
return ;
correctFile.close;
Read student answers from StudentAnswers.txt
string studentFileName;
cout "Enter the name of the student's file eg StudentAnswers.txt: ;
cin studentFileName;
fstream studentFileStudentAnswerstxt;
if studentFile
cerr "Error opening StudentAnswers.txt;
return ;
for int i ; i NUMQUESTIONS; i
if studentFile studentAnswersi
cerr "Error reading student answers
;
return ;
studentFile.close;
Evaluate student's performance
int numQuestionsMissed ;
cout
Questions missed by the student:
;
for int i ; i NUMQUESTIONS; i
if correctAnswersi studentAnswersi
cout "Question i : Correct Answer correctAnswersi
Student Answer studentAnswersi endl;
numQuestionsMissed;
Display results
cout
Total number of questions missed: numQuestionsMissed std::endl;
double percentageCorrect NUMQUESTIONSnumQuestionsMissed NUMQUESTIONS;
cout "Percentage of questions answered correctly: fixed setprecision percentageCorrect
;
if percentageCorrect
cout "Student passed the exam.
;
else
cout "Student failed the exam.
;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started