Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this final assignment, I have my code from IP 4 but I am struggling to get the program to run the test,

Need help with this final assignment, I have my code from IP 4 but I am struggling to get the program to run the test, please help.

Key Assignment Final Draft

Part 1: Begin with the running program from your Phase 4 Individual Project where the examination question class hierarchy was fully implemented in a menu-driven program. An exam class was developed to load the exam from a file and display each question to the screen.

Part 2: Modify the program from part 1 to change the menu to the following: Load an exam Take an exam Show exam results Quit

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

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

Choice 3: The program should display the total points available and the total points scored during that exam. A percentage score should also be displayed. (Optional: if you choose to track which problems were missed, you could display that information for the user.)

Choice 4: No change to this functionality from the Phase 4 IP. You should consider creating an additional class Student that will track student's score through methods such as addPointsPossible, addPointsScored, getPointsPossible, and getPointsScored. You should also enhance your Exam class to include methods getPointValue and getAnswer. You may also want to add a method to only display one question at a time, such as displayQuestion.

Here's my code so far:

//Include the required header files.

#include

#include

#include

#include

//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 the file.

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 << " File 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 the file.

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 MENU ";

cout << "1. Load an exam." << endl;

cout << "2. Display the exam." << endl;

cout << "3. Quit." << endl;

//Prompt the user to enter a choice.

cout << " Enter 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 << " Loaded successfully.";

//Prompt the user to enter the choice.

cout << " Do 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 << " The content of the file is as follows: ";

//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 << " The 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 << " Please enter a valid input.";

}

//Prompt the user to enter the choice.

cout << " Do you want to enter again? (y/n) : ";

//Update the value of the variable.

cin >> c;

}

//Display the exiting message.

cout << " Exiting from the program... Thank you!" << endl;

//Return 0 and exit from the program.

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

Students also viewed these Databases questions