Answered step by step
Verified Expert Solution
Link Copied!

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 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;
}

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions