answersLogoWhite

0


Best Answer

Assuming the quiz is a simple question/answer style quiz, use a map to associate question strings with answer strings. In order to prevent people from simply examining the program resources to get the answers, you should also consider encrypting the map.

For multiple choice quizzes, use a structure containing the question string, a vector of strings for the possible answers and an unsigned integer to identify the correct answer (as an index into the vector).

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

#include

#include

#include

#include

struct multi_choice

{

std::string question;

std::vector< std::string> choices;

unsigned answer;

multi_choice (

std::string q,

std::string c1,

std::string c2,

std::string c3,

std::string c4,

unsigned a);

const std::string& get_answer () const { return choices[answer-1]; }

};

// default constructor

multi_choice::multi_choice (

std::string q,

std::string c1,

std::string c2,

std::string c3,

std::string c4,

unsigned a)

: question (q), choices(), answer (a)

{

choices.push_back (c1);

choices.push_back (c2);

choices.push_back (c3);

choices.push_back (c4);

}

std::ostream& operator<< (std::ostream& os, const multi_choice& q)

{

os << q.question << '\n' << std::endl;

for (unsigned c=0; c<4; ++c)

os << c+1 << ") " << q.choices[c] << std::endl;

return os;

}

unsigned input_answer ()

{

unsigned num = 0;

while (1)

{

std::cout << "Your answer: ";

std::string input = "";

std::getline (std::cin, input);

std::stringstream ss (input);

if (ss >> num && num >= 1 && num <= 4)

break;

std::cout << "Invalid input.\n";

}

return (num);

}

int main()

{

std::vector questions;

questions.push_back ( multi_choice (

"In which direction does the sun rise in the morning?",

"East", "West", "North", "South", 1));

questions.push_back ( multi_choice (

"How long does a fortnight last?",

"A day", "A week", "Two weeks", "A month", 3));

// add other questions here....

unsigned points = 0;

for (unsigned q=0; q

{

std::cout << "Question " << q+1 << '\n' << std::endl;

std::cout << questions[q] << std::endl;

if (input_answer() == questions[q].answer)

{

std::cout << "Correct!" << std::endl;

++points;

}

else

{

std::cout << "Wrong!\nThe correct answer is ";

std::cout << questions[q].answer << ", ";

std::cout << questions[q].get_answer();

std::cout << std::endl;

}

std::cout << std::endl;

}

std::cout << "Quiz completed!\n" << std::endl;

std::cout << "You scored " << points;

std::cout << (points>1?" points!\n":" point!\n") << std::endl;

}

Example Output

Question 1

In which direction does the sun rise in the morning?

1) East

2) West

3) North

4) South

Your answer: 1

Correct!

Question 2

How long does a fortnight last?

1) A day

2) A week

3) Two weeks

4) A month

Your answer: 2

Wrong!

The correct answer is 3, Two weeks

Quiz completed!

You scored 1 point!

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you make quiz master in c plus plus programm?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Which quiz master host the bornvita quiz contest?

Sir Derek O'Brien is the quiz host of the CADBUARY BOURNVITA QUIZ CONTEST .And he is also the quiz master of the Asia.


What do you call a person who conducts a quiz?

Quiz Master


What do you call the person who conducts a quiz?

Quiz Master


What do you call someone who runs TV quiz shows?

Quiz Master


What is the nickname of the quiz master on university challenge?

_a_o


Who is the quiz master from University Challenge?

Jeremy paxman


What are the release dates for Inspector Gadget - 1983 Quiz Master 1-65?

Inspector Gadget - 1983 Quiz Master 1-65 was released on: USA: 9 December 1983


Which word can go after Harbor Quiz and Head to make three other words?

The word "master" can be added as a suffix to those words. Other words that create one-word forms, sometimes with idiomatic meanings, are load(master), scout(master), ring(master), and post(master).


What are the ratings and certificates for Inspector Gadget - 1983 Quiz Master 1-65?

Inspector Gadget - 1983 Quiz Master 1-65 is rated/received certificates of: Australia:G USA:TV-Y


Where can you make quiz's?

The quiz is easy to make with quiz maker software and 12 free online quiz makers. You can have a try through the folloing related links.


How do you make a quiz about yourself on Bebo?

Make sure you have the quiz module on your bebo page On your profile scroll down to the quiz module Click "Create Quiz"


How do you make a quiz like the impossible quiz?

The most important part is to just try to make the quiz really hard!