Hello, I am trying to take this step by step I code my True/False function complete but I am getting an error and need help figuring it out. I still need to do the Multiple Choice function as well but for now, need to get the True/False figured out.
//#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
usingnamespace 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;
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;
char answer, yn;
do
{
cout << "\nHow many points does this question worth? Enter: ";
cin >> points;
cin.ignore();
cout << "\nPlease enter the question: ";
getline(cin, question);
cout << "\nPlease 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;
//Complete the remaining code here
}
//Now you have to complete function MultipleChoice()
// function to create multiple choice question
void TestBank::MultipleChoice(ofstream& theFile)
{
}
Error:
Warning C4101 'yesOrNo': unreferenced local variable line 17
Error LNK1104 cannot open file 'C:\Users\ACEis\source\repos\CS215_Joseph_Hoffman_IP3\Debug\CS215_Joseph_Hoffman_IP3.exe' CS215_Joseph_Hoffman_IP3 C:\Users\ACEis\source\repos\CS215_Joseph_Hoffman_IP3\LINK line 1
void TestBank::TrueFalse(ofstream& thefile)
{
int points;
string question;
char answer, yn;
do
{
cout << "\nHow many points does this question worth? Enter: ";
cin >> points;
cin.ignore();
cout << "\nPlease enter the question: ";
getline(cin, question);
cout << "\nPlease 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 (commented out for testing)
//thefile << points << endl;
//thefile << question << endl;
//thefile << answer << endl;
//Complete the remaining code here
}
The program asks the following in order for the true/false section:
*How many points does this question worth? Enter:
*Please enter the question:
*Please enter the answer True or False?
*Would like to make any correction <y/n>?
If 'y' is selected it should loop back to the beginning to retry if 'n' the program should write all the inputs to the file.
I fixed my code. The thing I need help with now is when the program asks the user to hit 1 for TF (T/F) or 2 for MC (Multiple choice) when you hit 1 or 2 it stores 1 or 2 in the file I need it to store TF if you hit 1 or MC if you hit 2 in the file. How do I do this please help?
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
usingnamespace 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;
test << typeOfQuestion << 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 << "\nHow many points does this question worth? Enter: ";
cin >> points;
cin.ignore();
cout << "\nPlease enter the question: ";
getline(cin, question);
cout << "\nPlease 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)
{
}
The format stored in the file should look like this:
Test bank file format should look like the following example:
3
TF 5
Do pigs fly?
False
TF 2
Is programming important?
True
Currently, it looks like this:
3
1
5
Do pigs fly?
False
1
2
Is programming important?
True