Write a C++ program to allow the user to create a test bank of questions. The pr
ID: 3817996 • Letter: W
Question
Write a C++ program to allow the user to create a test bank of questions. The program should first ask the user how many questions he or she wishes to create. This quantity will be the first line in the test bank. The user should now be prompted for all information for each question, and then that question is written out to the test bank in the exact format specified in the Phase 2 Individual Project. For each question, the following information should be gathered: Question type: Multiple choice (MC) or True/False (TF) Question value Actual question If the question is TF, then get answer If the question is MC, then get the number of options followed by each option and finally the answer
Explanation / Answer
// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <stdlib.h> /* srand, rand */
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string.h>
using namespace std;
int main()
{
ofstream outFile;
outFile.open ("output.txt");
int totalQuestion;
string option, type, question, answer;
int totalOptions;
cout << "Enter total number of question: ";
cin >> totalQuestion;
outFile << totalQuestion << endl;
for (int i = 0; i < totalQuestion; ++i)
{
cout << " Question " << (i+1) <<endl;
cout << "Enter question type(TF/MC): ";
cin >> type;
if(type == "TF")
{
cin.ignore();
cout << "Enter question: ";
getline(cin,question);
cout << "Enter answer(True/False): ";
cin >> answer;
outFile << type << endl;
outFile << question << endl << answer << endl;
}
if(type == "MC")
{
cin.ignore();
cout << "Enter question: ";
getline(cin,question);
cout << "Enter number of options: ";
cin >> totalOptions;
outFile << type << endl;
outFile << question << endl;
for (int j = 0; j < totalOptions; ++j)
{
cin.ignore();
cout << "Enter option " << (j+1) <<": ";
getline(cin , option);
outFile << option << endl;
}
cout << "Enter answer(correct option): ";
cin >> answer;
outFile << answer << endl;
}
}
outFile.close();
return 0;
}
/*
output:
Enter total number of question: 2
Question 1
Enter question type(TF/MC): TF
Enter question: There exist birds that cannot fly?
Enter answer(True/False): true
Question 2
Enter question type(TF/MC): MC
Enter question: Who was the President of the USA in 1991?
Enter number of options: 4
Enter option 1: Richard Nixon
Enter option 2: Gerald Ford
Enter option 3: Jimmy Carter
Enter option 4: George Bush Sr.
Enter answer(correct option): D
output.txt
2
TF
There exist birds that cannot fly?
true
MC
Who was the President of the USA in 1991?
Richard Nixon
Gerald Ford
Jimmy Carter
George Bush Sr.
D
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.