Q Write a C++ program that is menu-driven that allows for the following menu choices: Load an exam: Loading an exam should prompt the user for an exam file. If no file exists, it should allow the user to specify a different file. Upon a successful load of an exam, the user should be presented with the menu again. Display exam: The program should simply display each question, its point value, and the answer to the screen. (The functionality of actually taking the exam will be created in Week 5). Upon displaying the exam to the screen, the user should be presented with the menu again. Quit: Quit the program gracefully by displaying a “thank you” message to the user, and ensure that all files have been closed along with any other housekeeping that should be done as your program shuts down. Consider creating a class exam that will hold the actual exam and provide behavior such as loadExam and also displayExam. This class will be enhanced in Week 5

As an advanced student with extensive knowledge in C++ programming, I will provide a detailed analysis and implementation plan for the given task.

To create a menu-driven program that allows for the specified menu choices, we will need to design a class, called “Exam,” which will hold the actual exam and provide the necessary behavior, such as loading and displaying the exam.

First, let’s define the Exam class and its member variables and functions:

class Exam {
// Member variables
std::string examFilePath;
bool examLoaded;

// Member functions
void loadExam();
void displayExam();

The Exam class has two member variables: `examFilePath` to store the path of the exam file, and `examLoaded` to track whether an exam has been successfully loaded or not.

Now, let’s define the member functions `loadExam` and `displayExam`:

void Exam::loadExam() {
std::string filePath;
std::cout << "Enter the path of the exam file: "; std::cin >> filePath;

// Check if the file exists
std::ifstream file(filePath);
if (!file) {
std::cout << "File does not exist.n"; return; } // Successfully loaded the exam file examFilePath = filePath; examLoaded = true; std::cout << "Exam loaded successfully.n"; } void Exam::displayExam() { // Check if an exam is loaded if (!examLoaded) { std::cout << "No exam loaded.n"; return; } // Read the exam file and display each question, point value, and answer std::ifstream file(examFilePath); // Read and display the exam content here // ... } ``` In the `loadExam` function, the user will be prompted to enter the path of the exam file. If the file does not exist, a message will be displayed, and the function will return. Otherwise, the exam file path will be stored in the `examFilePath` variable, and `examLoaded` will be set to `true`. In the `displayExam` function, it first checks if an exam is loaded by checking the `examLoaded` variable. If no exam is loaded, a message will be displayed, and the function will return. Otherwise, the exam file will be opened and read to display each question, point value, and answer on the screen. To implement the menu-driven program, we can create a main function that uses a while loop to repeatedly display the menu and process the user's choice: ```cpp int main() { Exam myExam; int choice; while (true) { std::cout << "Menu:n"; std::cout << "1. Load an examn"; std::cout << "2. Display examn"; std::cout << "3. Quitn"; std::cout << "Enter your choice: "; std::cin >> choice;

switch (choice) {
case 1:
case 2:
case 3:
std::cout << "Thank you. Exiting the program.n"; // Perform any necessary cleanup before exiting return 0; default: std::cout << "Invalid choice. Try again.n"; break; } } return 0; } ``` In the main function, an instance of the Exam class, called `myExam`, is created. The while loop displays the menu and prompts the user for a choice. Depending on the choice, the corresponding member function of the Exam class is invoked. For choice 3, a "thank you" message is displayed, and the program exits. This implementation provides the basic structure for a menu-driven program that allows the user to load and display an exam, as well as gracefully quit the program. In Week 5, we will enhance the Exam class to add the functionality of taking the exam.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.

Click Here to Make an Order Click Here to Hire a Writer