Menu

(Solved) : Modify Program Change Menu Following Load Exam Take Exam Show Exam Results Quit Choice 1 F Q37278151 . . .

Modify the program to change the menu to the following:

  1. Load an exam
  2. Take an exam
  3. Show exam results
  4. Quit

Choice 1: No functionality change. Load theexam based upon the user’s prompt for an exam file.

Choice 2: The program should display a singlequestion at a time and prompt the user for an answer. Based uponthe answer, it should track the score based upon a successfulanswer. Once a user answers the question, it should also displaythe correct answer with an appropriate message (e.g., “Good job” or”Better luck next time”) Upon completion of the exam, the programshould return the user to the menu.

Choice 3: The program should display the totalpoints available and the total points scored during that exam. Apercentage score should also be displayed. (Optional: if you chooseto track which problems were missed, you could display thatinformation for the user.)

Choice 4: No change to this functionality

You should consider creating an additional class Student thatwill track student’s score through methods such asaddPointsPossible, addPointsScored, getPointsPossible, andgetPointsScored. You should also enhance your Exam classto include methods getPointValue and getAnswer.You may also want to add a method to only display one question at atime, such as displayQuestion.

The input files example is below

3

TF 5

There exist birds that cannot fly?

true

MC 10

Who was the President of the USA in 1991?

6

Richard Nixon

Gerald Ford

Jimmy Carter

Ronald Reagan

George Bush Sr.

Bill Clinton

E

TF 10

The city of Boston hosted the 2004 Summer Olympics?

false

Existing code

//Include the required header files.

#include <iostream>

#include <cstdlib>

#include <string>

#include <fstream>

//Use the standard namespace.

using namespace std;

//Define the class Test.

class Test

{

private:

//Create an object of the string class to store the name of thefile.

string testfile;

public:

//Declare the default constructor.

Test();

//Declare the parameterized constructor.

Test(string);

//Declare the function to load the file.

bool loadfile();

//Declare the function to display the file.

void displayfile();

};

//Define the default constructor.

Test::Test()

{

//Initialize the file name with default value.

testfile = “”;

}

//Define the parameterized constructor.

Test::Test(string filename)

{

//Initialize the file name with the parameter.

testfile = filename;

}

//Define the function to load the file.

bool Test::loadfile()

{

//Open the file in read mode.

ifstream file(testfile.c_str());

//Check if the file exists or not.

if (!file)

{

//Display the error message.

cout << “nFile not found.”;

//Return the value false.

return false;

}

//Close the file.

file.close();

//Return the value true.

return true;

}

//Define the function to display the file.

void Test::displayfile()

{

//Open the file in read mode.

ifstream file(testfile.c_str());

//Create an object of the string class.

string temp;

//Start the while loop till end of file.

while (!file.eof())

{

//Read a line from the file and store in temp.

getline(file, temp);

//Display the string.

cout << endl << temp;

}

//Close the file.

file.close();

}

//Define the main() function.

int main()

{

//Create an object of string class to store the name of thefile.

string filename;

//Create variable to store the input.

bool check;

char c = ‘y’;

//Start the while loop.

while (c == ‘y’ || c == ‘Y’)

{

//Create a variable of int type.

int select = 0;

//Display the main menu.

cout << “EXAM MENUnn”;

cout << “1. Load an exam.” << endl;

cout << “2. Display the exam.” << endl;

cout << “3. Quit.” << endl;

//Prompt the user to enter a choice.

cout << “nEnter your choice : “;

//Store the user input.

cin >> select;

//Check if the user entered the first option.

if (select == 1)

{

//Prompt the user to enter the name of the file.

cout << “Enter the filename : “;

//Store the input in the string.

cin >> filename;

//Create an object of the Test class with the file name.

Test t(filename);

//Call the function to load the file.

check = t.loadfile();

//Check if the file exists or not.

if (check)

{

//Display status message.

cout << “nLoaded successfully.”;

//Prompt the user to enter the choice.

cout << “nDo you want to display the file? (y/n) : “;

//Store the input.

cin >> c;

//Check the value entered by the user.

if (c == ‘y’)

{

//Display the output message.

cout << “nThe content of the file is as follows:n”;

//Call the function to display the content of the file.

t.displayfile();

}

}

}

//Check if the user entered the second option.

else if (select == 2)

{

//Prompt the user to enter the name of the file.

cout << “Enter the filename : “;

//Store the input in the string.

cin >> filename;

//Create an object of the Test class with the file name.

Test t(filename);

//Call the function to load the file.

check = t.loadfile();

//Check if the file exists or not.

if (check)

{

//Display the output message.

cout << “nThe content of the file is as follows:”<< endl;

//Call the function to display the content of the file.

t.displayfile();

}

}

//Check if the user entered the third option.

else if (select == 3)

{

//Move out of the if conditions.

break;

}

//Move to the else case.

else

{

//Display the error message.

cout << “nPlease enter a valid input.”;

}

//Prompt the user to enter the choice.

cout << “nDo you want to enter again? (y/n) : “;

//Update the value of the variable.

cin >> c;

}

//Display the exiting message.

cout << “nExiting from the program… Thank you!”<< endl;

//Return 0 and exit from the program.

return 0;

}

Expert Answer


Answer to Modify the program to change the menu to the following: Load an exam Take an exam Show exam results Quit Choice 1: No fu…

OR