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 =...
Write a C-based language program in visual studio that uses an array of structs that stores...
Write a C-based language program in visual studio that uses an array of structs that stores student information including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,”). Write the same program in the same language without using structs.
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report...
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_grades.txt contains the student’s Last name , First name, SSN, Test1, Test2, Test3 and Test4. (25%) i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0    83.0 Generate the output Report File student_final.txt in the following format : LastName FirstName   SSN Test1   Test2   Test3   Test4 Average FinalGrade i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0   ...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
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 new website using C# & ASP.Net in Visual Studio: 1. Create a web page...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page to access a database and display the data from a table by providing an SQL statement. Create the page with these requirements:     create label, textbox and button     the textbox will capture the SQL statement     the button will process the statement and display the results 2. Add necessary data access pages to your project. 3. Display the data in Gridview
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT