Question: My Code isn't opening the files I have attached. What am I doing wrong? #include #include #include #include using namespace std; const int NUM _

My Code isn't opening the files I have attached. What am I doing wrong?
#include
#include
#include
#include
using namespace std;
const int NUM_QUESTIONS =20;
int main(){
char correctAnswers[NUM_QUESTIONS];
char studentAnswers[NUM_QUESTIONS];
// Read correct answers from CorrectAnswers.txt
fstream correctFile("CorrectAnswers.txt");
if (!correctFile){
cerr "Error opening CorrectAnswers.txt
";
return 1;
}
for (int i =0; i NUM_QUESTIONS; ++i){
if (!(correctFile >> correctAnswers[i])){
cerr "Error reading correct answers
";
return 1;
}
}
correctFile.close();
// Read student answers from StudentAnswers.txt
string studentFileName;
cout "Enter the name of the student's file (e.g., StudentAnswers.txt): ";
cin >> studentFileName;
fstream studentFile("StudentAnswers.txt");
if (!studentFile){
cerr "Error opening StudentAnswers.txt";
return 1;
}
for (int i =0; i NUM_QUESTIONS; ++i){
if (!(studentFile >> studentAnswers[i])){
cerr "Error reading student answers
";
return 1;
}
}
studentFile.close();
// Evaluate student's performance
int numQuestionsMissed =0;
cout "
Questions missed by the student:
";
for (int i =0; i NUM_QUESTIONS; ++i){
if (correctAnswers[i]!= studentAnswers[i]){
cout "Question " i +1": Correct Answer =" correctAnswers[i]
", Student Answer =" studentAnswers[i] endl;
++numQuestionsMissed;
}
}
// Display results
cout "
Total number of questions missed: " numQuestionsMissed std::endl;
double percentageCorrect = NUM_QUESTIONS-numQuestionsMissed *100.0/ NUM_QUESTIONS;
cout "Percentage of questions answered correctly: " fixed setprecision(2) percentageCorrect "%
";
if (percentageCorrect >=70.0){
cout "Student passed the exam.
";
}
else {
cout "Student failed the exam.
";
}
return 0;
}
 My Code isn't opening the files I have attached. What am

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!