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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
//Question.cpp
#include <iostream>
#include <string>
#include "Question.h"
#include <fstream>
Question::Question()
{
setTriviaQuestion();
setAnswerOne();
setAnswerTwo();
setAnswerThree();
setAnswerFour();
}
Question::Question(string question, string one, string two, string three,
string four, int answer) : triviaQuestion {question}, answerOne {one}, answerTwo {two},
answerThree {three}, answerFour {four}, correctAnswer {answer}
{}
void Question::setTriviaQuestion(string question)
{
ifstream infile;
infile.open("trivia.txt");
getline(infile, question);
infile.close();
triviaQuestion = question;
}
void Question::setAnswerOne(string one)
{
answerOne = one;
}
void Question::setAnswerTwo(string two)
{
answerTwo = two;
}
void Question::setAnswerThree(string three)
{
answerThree = three;
}
void Question::setAnswerFour(string four)
{
answerFour = four;
}
void Question::setCorrectAnswer(int answer)
{
correctAnswer = answer;
}
string Question :: getTriviaQuestion()
{
return triviaQuestion;
}
string Question::getAnswerOne()
{
return answerOne;
}
string Question::getAnswerTwo()
{
return answerTwo;
}
string Question::getAnswerThree()
{
return answerThree;
}
string Question::getAnswerFour()
{
return answerFour;
}
int Question::getCorrectAnswer()
{
return correctAnswer;
}
bool Question::checkGivenAnswer(int choosenNumber)
{
return (correctAnswer == choosenNumber);
}
//Lab7.cpp
#include <iostream>
#include <string>
#include "Question.h"
using namespace std;
int main()
{
const int trivia = 10;
int playerOne = 0;
int playerTwo = 0;
int playerOneScore = 0;
int playerTwoScore = 0;
Question triviaGame[trivia];
for (int i = 0; i < trivia/2; i++)
{
int choosenNumber = 0;
cout << "Player 1:" << endl;
cout << triviaGame[i].getTriviaQuestion() << endl;
cout << triviaGame[i].getAnswerOne() << endl;
cout << triviaGame[i].getAnswerTwo() << endl;
cout << triviaGame[i].getAnswerThree() << endl;
cout << triviaGame[i].getAnswerFour() << endl;
cout << "Choose an answer by entering a number 1 to 4: ";
cin >> choosenNumber;
if (triviaGame[i].checkGivenAnswer(choosenNumber) == true)
{
playerOneScore++;
};
}
for (int i = 5; i < trivia; i++)
{
int choosenNumber = 0;
cout << "Player 2:" << endl;
cout << triviaGame[i].getTriviaQuestion() << endl;
cout << triviaGame[i].getAnswerOne() << endl;
cout << triviaGame[i].getAnswerTwo() << endl;
cout << triviaGame[i].getAnswerThree() << endl;
cout << triviaGame[i].getAnswerFour() << endl;
cout << "Choose an answer by entering a number 1 to 4: ";
cin >> choosenNumber;
if (triviaGame[i].checkGivenAnswer(choosenNumber) == true)
{
playerTwoScore++;
};
}
cout << "Player 1 Scored : " << playerOneScore << endl;
cout << "Player 2 Scored : " << playerTwoScore << endl;
if (playerOneScore > playerTwoScore)
{
cout << "The winner is Player 1" << endl;
}
else if (playerOneScore < playerTwoScore)
{
cout << "The winnder is Player Two" << endl;
}
else if (playerOneScore == playerTwoScore)
{
cout << "The score is tied, no winner" << endl;
}
return 0;
}
//trivia.txt
What is Pi?
3.14
2.72
0
A Food
1
What is e?
3.14
2.72
0
A food
2
What is a cpu?
The Central Processing Unit
A brand of computer
The antivirus software
The memory of a computer.
1
What is the natural log of e?
1
13
3
1.826
1
What is the 1kg in pounds?
2.2
3.2
1.2
1
1
What is the speed of light?
200653789 m/s
8026453 m/s
100000000 m/s
299792458 m/s
4
What is the speed of sound?
502465 m/s
1200 m/s
340 m/s
100 m/s
3
What is the chemical formula for Diamond?
C
D
au
pg
2
What is the weight of the earth in tons?
6.39 x 10^23
5.98 x 10^21
8.47 x 10^22
1.04 x 10^22
2
What is the slowest color?
Viloet
Red
Blue
Green
1
| |