Write a C++ program that is menu-driven that allows for the following menu choic
ID: 3839204 • Letter: W
Question
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
Explanation / Answer
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
string LoadExam();
string DisplayExam();
int main()
{
int choice;
do
{
cout << "1) Load an Exam" << endl;
cout << "2) Display the Exam" << endl;
cout << "3) Quit Program" << endl;
cin >> choice;
switch(choice)
{
case 1:
LoadExam();
break;
case 2:
void printDisplayExam();
break;
case 3:
cout << "Thank you for visiting. See you again later..." << endl;
break;
default:
cout << "Invalid Option" << endl;
}
} while (choice >= 1 || choice <= 3);
return 0;
}
void printDisplayExam()
{
string type;
string question;
char answer;
int NumbQuestions;
int valueOfQuestion
if (type == "TF"){
cout << "Enter in the question:" << endl;
cin.ignore();
getline (cin, question);
cout << "Enter in the answer:" << endl;
cin >>answer;
cout << NumbQuestions << endl;
cout << type << " " << valueOfQuestion << endl;
cout << question << endl;
cout << answer << endl;
}
if(type == "MC"){
cout << "Enter in the question:" << endl;
cin.ignore();
getline (cin, question);
cout << "Enter in the number of choices:" << endl;
cin >> numbOfChoices;
cout << "Enter in the options:" << " Place a space before each entry"<< endl;
for(int i = 0; i < numbOfChoices; i++){
cin.ignore();
getline (cin, opt[i]);
}
cout << "Enter in the answer:" << endl;
cin >> answer;
cout << NumbQuestions << endl;
cout << type << " " << valueOfQuestion << endl;
cout << numbOfChoices << endl;
cout << question << endl;
for(int j = 0; j < numbOfChoices; j++){
cout << opt[j] << endl;
}
cout <<"Answer: "<< answer << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.