Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ help to make Multiple choice function for testbank file I/O program. I made

ID: 3894968 • Letter: C

Question

C++ help to make Multiple choice function for testbank file I/O program. I made the function I just need help figuring out how to do the choices for it. Below is my code and the pseudo code to assist.

Pseudocode:

If MC question, then

i. Ask how many points the question worth.

ii. Enter the question. iii. Ask home many options, say OP

iv. Loop 1 to OP

1a. Enter the option.

2a. Repeat step iv until reaches value OP

v. Enter the answer to the question.

The output stored in the file for the MC should look like this example (I did not include the TF this is only selecting MC what it should look like):

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

My code:

#include "stdafx.h"

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

class TestBank

{

public:

void TrueFalse(ofstream&);

void MultipleChoice(ofstream&);

};

int main()

{

TestBank bankObj;

ofstream test;

int testNumber, typeOfQuestion;

char yesOrNo;

// Create test bank file.

test.open("C:\temp\testBankFile.txt");

if (test.is_open())

{

cout << "How many questions would you like to create? ";

cin >> testNumber;

test << testNumber << endl;

int nextNum = 1;

//create the test bank

for (int i = testNumber; i > 0; --i)

{

cout << endl << "What type of question will #" << nextNum++

<< " be? 1=T/F or 2=multiple choice: ";

cin >> typeOfQuestion;

if (typeOfQuestion == 1)

test << "TF ";

else if (typeOfQuestion == 2)

test << "MC ";

else

cout << "Invalid option" << endl;

switch (typeOfQuestion)

{

case 1: bankObj.TrueFalse(test);

break;

case 2: bankObj.MultipleChoice(test);

}

}

test.close();

}

else

{

cout << "Unable to create test bank";

}

system("pause");

return 0;

}

// function to create true/false question

void TestBank::TrueFalse(ofstream& thefile)

{

int points;

string question;

string answer;

char yn;

do

{

cout << " How many points does this question worth? Enter: ";

cin >> points;

cin.ignore();

cout << " Please enter the question: ";

getline(cin, question);

cout << " Please enter the answer True or False ? ";

cin >> answer;

cin.ignore();

cout << "Would like to make any correction <y/n>? ";

cin >> yn;

} while (yn == 'y');

//Write all information into the file

thefile << points << endl;

thefile << question << endl;

thefile << answer << endl;

}

//Now you have to complete function MultipleChoice()

// function to create multiple choice question

void TestBank::MultipleChoice(ofstream& theFile)

{

}

I also need to make the program read in the file after all information is collected to display out the collected information from the file. The result should look like this:

This means the output file would look like this:

3
TF 5
There exists 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

Please assist me with primarily the MC function located at the bottom of the code. Second, displaying the results before exiting the program from the data saved to the file from the program read back in.

S215-Joseph-Hoffman-P2 (Running) Microsoft Visual Studio Quick Launch (Ctrl-O) File Edit iew Project Build Debug Team Tools Test Analyze Window Help Joe HottmanJH Continue a ? ?- , Application Insights*- Process: [45800] CS21 5Joseph-HoffrnanJF ? -? C5215 Joseph _Hoffm CAUsers ACEistsourcerepos CS215 Joseph_Hoftman IP2Debug CS215 Joseph Hoffman IP2.exe There exists birds that cannot fly? CS215 Joseph Ho e4 49 seconds rue 50s Gerald Ford immy Carter Ronald Reagan .George Bush Sr. 374 for (int E. Bill Clinton 100 Swer: city of Boston hosted the 2004 Summer Olympics? Memory Usage CPU Usage alse of Dl 67 % Narrie 4vcruntime14ed.dll'. Cann tucrtbased.dll. Cannot f 4msvep140d.d11'. Cannot f W64msvcp148d.dl1 4nsvcp148d.dll'. Cannot f Autos Locals Watch 1 Call Stack Breakpoints Exception Settings Command Window Immediate Window Output Error List Add to Source Control ? a ) ENG 5:17 PM E

Explanation / Answer

Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#include "stdafx.h"

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

class TestBank

{

public:

void TrueFalse(ofstream&);
void MultipleChoice(ofstream&);
void PrintTest(ifstream& );
};

int main()

{

TestBank bankObj;

ofstream test;

int testNumber, typeOfQuestion;

char yesOrNo;

// Create test bank file.
string filename = "C:\temp\testBankFile.txt";
test.open(filename.c_str());

if (test.is_open())

{

cout << "How many questions would you like to create? ";

cin >> testNumber;

test << testNumber << endl;

int nextNum = 1;

//create the test bank

for (int i = testNumber; i > 0; --i)

{

cout << endl << "What type of question will #" << nextNum++

<< " be? 1=T/F or 2=multiple choice: ";

cin >> typeOfQuestion;

if (typeOfQuestion == 1)

test << "TF ";

else if (typeOfQuestion == 2)

test << "MC ";

else

cout << "Invalid option" << endl;

switch (typeOfQuestion)

{

case 1: bankObj.TrueFalse(test);

break;

case 2: bankObj.MultipleChoice(test);

}

}

test.close();

cout << endl << endl << "==================== Test Questions ====================" << endl;
ifstream in(filename.c_str());
bankObj.PrintTest(in);
in.close();
}

else

{

cout << "Unable to create test bank";

}

system("pause");

return 0;

}

// function to create true/false question

void TestBank::TrueFalse(ofstream& thefile)

{

int points;

string question;

string answer;

char yn;

do

{

cout << " How many points does this question worth? Enter: ";

cin >> points;

cin.ignore();

cout << " Please enter the question: ";

getline(cin, question);

cout << " Please enter the answer True or False ? ";

cin >> answer;

cin.ignore();

cout << "Would like to make any correction <y/n>? ";

cin >> yn;

} while (yn == 'y');

//Write all information into the file

thefile << points << endl;
thefile << question << endl;
thefile << answer << endl;

}

//Now you have to complete function MultipleChoice()

// function to create multiple choice question


void TestBank::MultipleChoice(ofstream& theFile)
{
int points;
string question;
string options[10];
int numOptions;
char op = 'A', correct;
char yn;
do
{
cout << " How many points does this question worth? Enter: ";
cin >> points;
cin.ignore();
cout << " Please enter the question: ";
getline(cin, question);
cout << "How many options? ";
cin >> numOptions;
cin.ignore();
op = 'A';
for(int i = 1; i <= numOptions; i++, op++)
{
cout << "Enter option " << op << ": ";
getline(cin, options[i-1]);
}
cout << "Enter the correct option: ";
cin >> correct;
cout << "Would like to make any correction <y/n>? ";
cin >> yn;
} while (yn == 'y');
theFile << points << endl;
theFile << question << endl << numOptions << endl;
for(int i = 0; i < numOptions; i++)
theFile << options[i] << endl;
theFile << correct << endl;
}

void TestBank::PrintTest(ifstream& in)
{
int numQs;
int numOptions;
int points;
string question, option, ans;
string type;

in >> numQs;

for(int i = 1; i <= numQs; i++)
{
in >> type >> points;
in.ignore();
getline(in, question);

cout << question << endl;

if(type == "TF")
{
getline(in, ans);
cout << ans << endl;
}
else
{
in >> numOptions;
in.ignore();
char op = 'A';
for(int j = 1; j <= numOptions; j++, op++)
{
getline(in, option);
cout << op << ". " << option << endl;
}
getline(in, ans);
cout << "Answer: " << ans << endl;

}

cout << endl;

}

}


output
=====
How many questions would you like to create? 3

What type of question will #1 be? 1=T/F or 2=multiple choice: 1

How many points does this question worth? Enter: 5

Please enter the question: There exists birds that cannot fly?

Please enter the answer True or False ? true
Would like to make any correction <y/n>? n

What type of question will #2 be? 1=T/F or 2=multiple choice: 2

How many points does this question worth? Enter: 10

Please enter the question: Who was the President of the USA in 1991?
How many options? 6
Enter option A: Richard Nixon
Enter option B: Gerald Ford
Enter option C: Jimmy Carter
Enter option D: Ronald Reagan
Enter option E: George Bush Sr.
Enter option F: Bill Clinton
Enter the correct option: E

What type of question will #3 be? 1=T/F or 2=multiple choice: 1

How many points does this question worth? Enter: 10

Please enter the question: The city of Boston hosted the 2004 Summer Olympics?

Please enter the answer True or False ? false
Would like to make any correction <y/n>? n

==================== Test Questions ====================
There exists birds that cannot fly?
true

Who was the President of the USA in 1991?
A. Richard Nixon
B. Gerald Ford
C. Jimmy Carter
D. Ronald Reagan
E. George Bush Sr.
F. Bill Clinton
Answer: E

The city of Boston hosted the 2004 Summer Olympics?
false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote