Question

In: Computer Science

Write a C++ program to read in various types of test questions (multiple choice and True/False)...

Write a C++ program to read in various types of test questions (multiple choice and True/False) from a test bank (text file), and load the questions into an array of questions. You will need to implement the following class hierarchy (given in UML):

Once the test bank has been loaded, simply iterate over the array of questions and have each question printed out to the screen.

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".

For this assignment, you may download this sample code for reference. A sample test bank file is as follows:

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

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// questions.txt

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

____________________________

#include <iostream>

#include <string>

#include <fstream>

#include <cstdlib>

using namespace std;

int main() {
//Declaring variables
ifstream dataIn;
string type, str, ans;
int cnt = 0, num;
int score;

//Opening the input file
dataIn.open("questions.txt");

//checking whether the file name is valid or not
if (dataIn.fail()) {
cout << "** File Not Found **";
exit(0);
} else {
getline(dataIn, str);
cnt = atoi(str.c_str());

// Creating array dynamically
string * questions = new string[cnt];
for (int i = 0; i < cnt; i++) {
getline(dataIn, str);

int indx = str.find(" ");

type = str.substr(0, indx);

score = atoi(str.substr(indx + 1, str.length()).c_str());

if (type.compare("TF") == 0) {

getline(dataIn, str);

questions[i] = str;

getline(dataIn, ans);

} else if (type.compare("MC") == 0) {
getline(dataIn, str);
questions[i] = str;
getline(dataIn, str);
num = atoi(str.c_str());
for (int i = 0; i < num; i++) {
getline(dataIn, str);
}
getline(dataIn, ans);
}

}
dataIn.close();

cout << "Displaying the questions :" << endl;
for (int i = 0; i < cnt; i++) {
cout << questions[i] << endl;
}
}
return 0;
}

____________________________

Output:

_______________Could you plz rate me well.Thank You


Related Solutions

Steve is about to write a test with 10 true or false questions and 15 multiple...
Steve is about to write a test with 10 true or false questions and 15 multiple choice questions. Steve has been studying hard so we’ll give a 75% chance of getting any of the 25 questions right. Assume all the questions are independent of each other. (a) (2 points) What is the probability that Steve gets exactly two thirds of the multiple choice questions right? (b) (3 points) What is the probability that Steve gets exactly half the true or...
PART 6: True or false and multiple-choice questions Question 16: True or false, firms in situation...
PART 6: True or false and multiple-choice questions Question 16: True or false, firms in situation of monopolistic competition have deadweight losses associated with monopoly because of barriers to entry. Question 17: Which of the two demands functions below is most elastic A) Qa=100-2p B) Qb=120-p Question 18: If a buyer values an object for $4 and a seller’s cost is $1, which of the statements below is false! If a transaction takes place, total surplus will be equal to...
Mary's Final for Psychology has 10 True/False questions and 10 multiple choice questions with 4 choices...
Mary's Final for Psychology has 10 True/False questions and 10 multiple choice questions with 4 choices for each answer. Assuming Mary randomly guesses on every question: a.) What's the probability that she gets at least 6 of the 10 true/false questions correct? b.) What's the probability that she gets at least 6 of the 10 multiple choice questions correct? c.) If the multiple choice questions had 5 choices for answers instead of 4, what's the probability that she gets at...
True/ False Questions: For the following questions, first write whether they are true or false then...
True/ False Questions: For the following questions, first write whether they are true or false then write in a few sentences why it’s true or false. (1.5) a. The processes for producing penicillin and blue cheese both use the Penicillium fungus.     b. The reproductive organs of Amanita muscaria are popular pizza toppings.     c. The fungus Claviceps purpurea is thought to have triggered the infamous Salem witch trials.     d. Saccharomyces cerevisiae is a common household bread mold.    ...
. Write a C program that asks the user a multiple-choice question and shows four possible...
. Write a C program that asks the user a multiple-choice question and shows four possible answers, (a) through (d). Prompt the user to input a response as a character. If the user enters the correct response, print a message stating that the answer is correct. If the user enters an incorrect response, print a message stating that the answer is wrong. If the user enters anything other than the letters a, b, c, or d, print a message stating...
Develop an interactive quiz. It should ask the user three multiple-choice or true/false questions about something....
Develop an interactive quiz. It should ask the user three multiple-choice or true/false questions about something. It must keep track of how many they get wrong, and print out a "score" at the end. (Assume data sensibly and also describe it question 2 ) OUTPUT : Are you ready for a quiz ? Y Okay, here are the questions! Q1) Which is the biggest animal? 1) Tiger 2) Rat 3) Elephant >3 That’s right! Q2) What is the result of...
Please answers the below True/False and Multiple choice questions from Business Law. (Please provide a brief...
Please answers the below True/False and Multiple choice questions from Business Law. (Please provide a brief explanation to answers if possible) Chapter: Agency Relationships 1. “By definition, independent contractors are not employees.” True/False 2.   John lies and tells Bill that he, John, is Mike's agent, when he is not. Bill enters into a contract with John for the benefit of Mike. Mike can still ratify the contract John entered into for him. True/False 3. In #2 above, when John lied,...
Please answers the below True/False and Multiple choice questions from Business Law. (Please provide a brief...
Please answers the below True/False and Multiple choice questions from Business Law. (Please provide a brief explanation to answers if possible) Chapter: Business Organizations 1.   The business judgment rule does not immunize members of boards of directors from liability to stockholders that come about from the bad business decisions of those directors. True/False 2. Corporations are not required to incorporate under the law of the state where their corporate headquarters is located. True/False 3. The portion of a corporation’s profits...
Please answers the below True/False and Multiple choice questions from Business Law. (Please provide a brief...
Please answers the below True/False and Multiple choice questions from Business Law. (Please provide a brief explanation to answers if possible) Chapter: Securities Law 1.             The first state law regulating the sale of securities was referred to in the book as the Kansas ______ law:                 a.            state securities                 b.             green stock                 c.             red flag                 d.            blue sky 2.             Which of the following best describes the so-called Howey test?                 a.             the investment of money b. a...
A multiple-choice test consists of 22 questions with possible answers of a, b, c, d, e,...
A multiple-choice test consists of 22 questions with possible answers of a, b, c, d, e, f. Estimate the probability that with random guessing, the number of correct answers is at least 11. the answer is not 0.0016 or 0.21
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT