-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestions.cpp
More file actions
79 lines (65 loc) · 1.6 KB
/
Copy pathQuestions.cpp
File metadata and controls
79 lines (65 loc) · 1.6 KB
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
#include "Questions.h"
//DEFAULT CONSTRUCTOR
Question::Question() {
}
//COPY CONSTRUCTOR
Question::Question(string newQuestion, vector<string> newAnswers, int newCorrectAnswer, bool newState) {
question = newQuestion;
answers = newAnswers;
correctAnswer = newCorrectAnswer;
state = newState;
}
//DECONSTRUCTOR
Question::~Question(){
}
//Accessor functions
string Question::getQuestion() const{
return question;
}
string Question::getAnswers(int i) const{
return answers[i];
}
unsigned int Question::getVectorSize() const {
return answers.size();
}
int Question::getCorrectAnswer() const{
return correctAnswer;
}
bool Question::getState() const{
return state;
}
//Mutator functions
void Question::setQuestion(string modquestion){
modquestion = question;
}
//Operator overloading
ostream& operator<< (ostream &out, const Question &q) {
unsigned int vecSize = q.answers.size();
out << q.question << endl;
out << vecSize << endl;
for (unsigned int x = 0; x < vecSize; x++) {
out << q.answers[x] << endl;
}
out << q.correctAnswer << endl;
return out;
}
istream& operator>> (istream &in, Question &q) {
string buff = ""; //buffer for stoi conversion
q.state = true;
getline(in, buff);
if (buff == "") {
q.state = false;
return in;
}
q.question = buff; //loads question
int vecSize = 0;
getline(in, buff);
vecSize = stoi(buff);
for(int i = 0; i < vecSize; i++) {
getline(in,buff);
q.answers.push_back(buff);
}
getline(in, buff);
q.correctAnswer = stoi(buff);
return in;
}