Question

In: Computer Science

Create a question bank. The language is visual studio c++. Description: Question bank computerizes the MCQ...

Create a question bank. The language is visual studio c++.

Description:
Question bank computerizes the MCQ based exams.It takes input from a file having questions and their answers
and presents randomly before the exam takers.

Required skill set: OOP, STL(Vector), Arrays and file handling

Solutions

Expert Solution

#include <iostream>

#include <sstream>

#include <fstream>

#include <cstdlib>

#include <vector>

using namespace std;

class MCQ

{

private:

string question, opt1, opt2, opt3, opt4;

char correct;

public:

MCQ()

{

this->question = "";

this->opt1 = "";

this->opt2 = "";

this->opt3 = "";

this->opt4 = "";

this->correct = 0;

}

MCQ(string ques, string opt1, string opt2, string opt3, string opt4, char corr)

{

this->question = ques;

this->opt1 = opt1;

this->opt2 = opt2;

this->opt3 = opt3;

this->opt4 = opt4;

this->correct = corr;

}

string getQuestion(){ return this->question; }

string getOption1(){ return this->opt1; }

string getOption2(){ return this->opt2; }

string getOption3(){ return this->opt3; }

string getOption4(){ return this->opt4; }

char getCorrect(){ return this->correct; }

string toString()

{

stringstream ss;

ss << "Question: " << question << " ?" << endl << "a. " << opt1 << "\nb. " << opt2 << "\nc. " << opt3 << "\nd. " << opt4;

return ss.str();

}

};

void splitIntoTokens(string const &str, const char delimiter, vector<string> &res);

int main()

{

ifstream inFile("questions.txt");

vector<MCQ> mcqs;

int correctAnswers = 0;

if(!inFile.is_open())

{

cout << "Could not open file: questions.txt" << endl;

exit(0);

}

string line;

while(getline(inFile, line))

{

const char delimiter = ',';

vector<string> result;

splitIntoTokens(line, delimiter, result);

string question = result[0];

string option1 = result[1];

string option2 = result[2];

string option3 = result[3];

string option4 = result[4];

char correct = result[5][0];

mcqs.push_back(MCQ(question, option1, option2, option3, option4, correct));

}

inFile.close();

cout << endl;

int nQuestions = mcqs.size();

char yesNo;

do

{

int picker = rand() % nQuestions + 0;

cout << mcqs[picker].toString() << endl;

char correct = mcqs[picker].getCorrect();

char choice;

cout << "Your answer (a/b/c/d): ";

cin >> choice;

while(choice != 'a' && choice != 'b' && choice != 'c' && choice != 'd')

{

cout << choice << " is not a valid choice" << endl;

cout << "Your answer (a/b/c/d): ";

cin >> choice;

}

if(choice == correct)

correctAnswers++;

cout << endl << "Continue?[y/n]: ";

cin >> yesNo;

if(yesNo == 'N' || yesNo == 'n')

{

cout << "\nYour score: " << correctAnswers << endl << "Thank you...Good Bye!\n";

exit(0);

}

cout << endl;

}while(yesNo != 'N' || yesNo != 'n');

}

void splitIntoTokens(string const &str, const char delimiter, vector<string> &res)

{

stringstream ss(str);

string s;

while(getline(ss, s, delimiter))

{

res.push_back(s);

}

}

**************************************************************** SCREENSHOT ***********************************************************

INPUT FILE (questions.txt):


Related Solutions

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
In Assembly Language (Visual Studio 2017), create a procedure that generates a random string of Length...
In Assembly Language (Visual Studio 2017), create a procedure that generates a random string of Length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer to an array of byte that will hold the random string. Write a test program that calls your procedure 20 times and displays the strings in the console window. In your program, the random string size shall be preset as a constant. Please include...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio development environment 3. To practice on writing a C# program Task 1: Create documentation for the following program which includes the following: a. Software Requirement Specification (SRS) b. Use Case Task 2: Write a syntactically and semantically correct C# program that models telephones. Your program has to be a C# Console Application. You will not implement classes in this program other than the class...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT