Multiple Choice
Mar 10, 2014 at 5:45am UTC
Hi I was going to create a multiple choice quiz where the question was being input to a vector and then to a text file. Then it will display the questions from the text file.
Can you help me, even just with the part where i can input strings into vector, and how can i make this a multiple choice exam. Here is what I have so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main()
{
vector<string> questionlist;
vector<string>::const_iterator iter;
string addQuestion;
int removeNumber;
int choice;
cout << endl << endl << "Multiple Choice System" << endl << endl;
int number = 0;
do
{
cout << "\n1. Take Test." << endl;
cout << "\n2. Add question to the list." << endl;
cout << "\n3. Remove a question from the list." << endl << endl;
cout << "\n4. Quit the program." << endl << endl;
cout << "Choose: " ;
cin >> choice;
switch (choice)
{
case 1:
for (iter = questionlist.begin(); iter != questionlist.end(); iter++)
{
cout << "\n" << *iter << endl;
}
break ;
case 2:
cout << "\nWrite the question:" ;
cin.ignore();
getline(cin,addQuestion);
questionlist.push_back(addQuestion);
sort(questionlist.begin(), questionlist.end());
cout << endl << "Question added succesfully." << endl;
break ;
case 3:
for (iter = questionlist.begin(); iter != questionlist.end(); ++iter)
{
++number;
cout << number << ". " << *iter << endl;
}
cout << endl << "Type the number of the question you want to remove below." << endl;
cout << "Remove number: " ;
cin >> removeNumber;
questionlist.erase(questionlist.begin() + removeNumber - 1);
cout << endl <<"Question removed." << endl;
number = 0;
for (iter = questionlist.begin(); iter != questionlist.end(); ++iter)
{
++number;
cout << number << ". " << *iter << endl;
}
}
}while (choice !=4);
return 0;
}
Topic archived. No new replies allowed.