Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

8. Providing support during instruction.

Answered: 1 week ago