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.
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...
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT