In this program exercise you will create a simple trivia gam

In this program exercise you will create a simple trivia game for two players. The program will work like this:

Starting with player 1, each player gets a turn at answering 5 trivia questions. (There should be a total of 10 questions.) When a question is displayed, 4 possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point.

After answers have been selected for all the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner.

To create this program, write a Question class to hold the data for a trivia question. The Question class should have attributes for the following data:

A trivia question

Possible answer 1

Possible answer 2

Possible answer 3

Possible answer 4

The number of the correct answer (1, 2, 3, or 4)

The Question class also should have an appropriate __init__ method, accessors, and mutators.

The program should have a list or a dictionary containing 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subjects of your choice for the objects. Needs to be written in python 3

Solution

#include \"stdafx.h\" #include \"question.h\" #include #include #include using namespace std; void questionAns(question[], int); int main() {//start of function main question trivia[10]; //10 instances of Game class int count = 0; //used to count through loop and as index //variables to hold players answers int onechoice; int twochoice; //holds total points for each player int onePoints = 0; int twoPoints = 0; int x; cout << \"Let\'s test your computer knowledge.\" << endl; //creating questions and answer in each object // QUESTION ONE trivia[0].setQues(\"Who is father of modern computers?\"); trivia[0].setAnswer1(\"1. Abraham Lincoln\"); trivia[0].setAnswer2(\"2. James Gosling\"); trivia[0].setAnswer3(\"3. Charles Babbage\"); trivia[0].setAnswer4(\"4. Gordon.E.Moore\"); trivia[0].setCorrect(3); // QUESTION TWO trivia[1].setQues(\"What does HTTP stands for?\"); trivia[1].setAnswer1(\"1. Head Tail Transfer Protocol\"); trivia[1].setAnswer2(\"2. Hypertext Transfer Protocol\"); trivia[1].setAnswer3(\"3.Hypertext Transfer Plotter\"); trivia[1].setAnswer4(\"4.Hypertext Transfer Plot\"); trivia[1].setCorrect(2); // QUESTION THREE trivia[2].setQues(\"The term \'Pentium\' is related to?\"); trivia[2].setAnswer1(\"1. DVD\"); trivia[2].setAnswer2(\"2. Hard Disk\"); trivia[2].setAnswer3(\"3.Microprocessor\"); trivia[2].setAnswer4(\"4.Mouse\"); trivia[2].setCorrect(3); // QUESTION FOUR trivia[3].setQues(\"Which computer memory is used for storing programs and data currently being processed by the CPU ?\"); trivia[3].setAnswer1(\"1. Internal memory\"); trivia[3].setAnswer2(\"2.Mass Memory\"); trivia[3].setAnswer3(\"3.Non volatile Memory\"); trivia[3].setAnswer4(\"4.PROM\"); trivia[3].setCorrect(1); // QUESTION FIVE trivia[4].setQues(\"Which of the following is used for close a tab on a browser?\"); trivia[4].setAnswer1(\"1. Ctrl+Y\"); trivia[4].setAnswer2(\"2. Ctrl+A\"); trivia[4].setAnswer3(\"3. Ctrl+W\"); trivia[4].setAnswer4(\"4.Ctrl+T\"); trivia[4].setCorrect(3); // QUESTION SIX trivia[5].setQues(\"Which of the following is a correct format of Email address?\"); trivia[5].setAnswer1(\"1.care@website.com\"); trivia[5].setAnswer2(\"2.care@website@com\"); trivia[5].setAnswer3(\"3.carewebsite.com\"); trivia[5].setAnswer4(\"4.care.website.com\"); trivia[5].setCorrect(1); // QUESTION SEVEN trivia[6].setQues(\"The process of transferring files from a computer on the Internet to your computer is called?\"); trivia[6].setAnswer1(\"1.Downloading\"); trivia[6].setAnswer2(\"2.FTP\"); trivia[6].setAnswer3(\"3.Forwarding\"); trivia[6].setAnswer4(\"4.Uploading\"); trivia[6].setCorrect(1); // QUESTION EIGHT trivia[7].setQues(\"The main working memory used by the computer are ?\"); trivia[7].setAnswer1(\"1.RAM\"); trivia[7].setAnswer2(\"2.ROM\"); trivia[7].setAnswer3(\"3.DVD\"); trivia[7].setAnswer4(\"4.CD\"); trivia[7].setCorrect(1); // QUESTION NINE trivia[8].setQues(\"Verification of a login name and password is known as?\"); trivia[8].setAnswer1(\"1.Configuration\"); trivia[8].setAnswer2(\"2.authentication\"); trivia[8].setAnswer3(\"3.accessibility\"); trivia[8].setAnswer4(\"4.logging in\"); trivia[8].setCorrect(1); // QUESTION TEN trivia[9].setQues(\"A byte consist of how many bits?\"); trivia[9].setAnswer1(\"1.8\"); trivia[9].setAnswer2(\"2.9\"); trivia[9].setAnswer3(\"3.10\"); trivia[9].setAnswer4(\"4.16\"); trivia[9].setCorrect(3); while(count < 9, count++) {//start while loop for actual game cout << setw(10) << \" QUESTION \" << (count + 1) << endl; questionAns(trivia,count); cout << \"Player 1\'s answer: \"; cin >> onechoice; cout << \"Player 2\'s answer: \"; cin >> twochoice; //if statements check to see if answers are right, if they are right then they get a point if(trivia[count].getCorrect() == onechoice) { onePoints++; } if(trivia[count].getCorrect() == twochoice) { twoPoints++; } cout << endl << endl; } if ( onePoints == twoPoints) { cout << \"Both players were tied.\" << endl; } if ( onePoints > twoPoints) { cout << \"Player one wins!\" << endl; }else { cout << \"Plaer two wins!\" << endl; } cout << \"Thanks for playing, press any key to exit.\"; cin >> x; } void questionAns(question z[], int count) { cout << z[count].getQues() << endl; cout << z[count].getAnswer1() << endl; cout << z[count].getAnswer2() << endl; cout << z[count].getAnswer3() << endl; cout << z[count].getAnswer4() << endl; } /* accessors and mutators for the question class */ #include \"stdafx.h\" #include #include \"question.h\" using namespace std; //mutators void question::setQues(string q) { ques = q; } void question::setAnswer1(string a1) { answer1 = a1; } void question::setAnswer2(string a2) { answer1 = a2; } void question::setAnswer3(string a3) { answer1 = a3; } void question::setAnswer4(string a4) { answer1 = a4; } void question::setCorrect(int correct) { correctnum = correct; } //accessors string question::getQues() const { return ques; } string question::getAnswer1() const { return answer1; } string question::getAnswer2() const { return answer2; } string question::getAnswer3() const { return answer3; } string question::getAnswer4() const { return answer4; } int question::getCorrect() const { return correctnum; }; #include #include using namespace std; class question { private: string ques; string answer1; string answer2; string answer3; string answer4; int correctnum; public: void setQues(string ques); void setAnswer1(string a1); void setAnswer2(string a2); void setAnswer3(string a3); void setAnswer4(string a4); void setCorrect(int correct); string getQues() const; string getAnswer1() const; string getAnswer2() const; string getAnswer3() const; string getAnswer4() const; int getCorrect() const; };
In this program exercise you will create a simple trivia game for two players. The program will work like this: Starting with player 1, each player gets a turn
In this program exercise you will create a simple trivia game for two players. The program will work like this: Starting with player 1, each player gets a turn

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site