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

Write a C++ program to read in various types of test questions (multiple choice

ID: 3661483 • Letter: W

Question

Write a C++ program to read in various types of test questions (multiple choice and True/False) from a test bank (text file), The test bank (text file) will have the following format: Line 1 will be an integer value, indicating how many questions in the file Each question will start with a line that starts with either "MC" or "TF" followed by a space and then the point value of the question. The next line will be the actual question. If the question was True/False, the following line will be the answer, either "True" or "False" If the question was multiple choice, the following line will be an integer value indicating how many choices will be provided for that question. The following lines will be the choices. There will never be more than 6 choices. The final line following the choices will be the answer: "A" or "B" or "C" or "D" or "E" or "F". 3 TF 5 There exist 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

Explanation / Answer

The following is the program along with comments:

#include <iostream>

#include <string>

#include <fstream>

class test_questions

{

private:

               int score;

               int numberofQuestions;

               int numberofAnswers;

               std::string questionType;

               int questionValue;

               std::string question;

               std::string mcAnswers[10];

               std::string answer;

               std::fstream testData;

               bool opentest(std::string);

               void closetest();

               void dotest();

public:

               test_questions();

               bool Run(std::string);

};

test_questions::test_questions()

{

               score = 0;

}

bool test_questions::opentest(std::string Test)/* functions opens the file*/

{

               testData.open(Test, std::ios::in);

               if (testData.fail())

                               return false;

               return true;

}

void test_questions::closetest() /*functions closes the file test */

{

               testData.close();

}

void test_questions::dotest() /*performs the operations here*/

{

               std::string data;

               std::string qData; /*question data*

               std::string aData; /*answer data */

               std::string mcData;   /*multiple choice data here */

               getline(testData, data);

               numberofQuestions = stoi(data);

bool test_questions::Run(std::string Test)

{

               if (opentest(Test)) {

                               doQuestions();

                               closetest();

               }

               else

                               return false;

               return true;

}

int _tmain(int argc, _TCHAR* argv[])

{

               test_questions Game;

               if (!Game.Run("Test.txt"))

                               std::cout << "test doest begin if there is no data in the test file.";

               system("pause");

               return 0;

}

OUTPUT:

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