-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question.cpp
134 lines (107 loc) · 4.15 KB
/
Question.cpp
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
#include "Question.h"
#include "HelperFunction.h"
Question::Question()
: question_id(-1),
parent_question_id(-1),
from_user_id(-1),
to_user_id(-1),
is_anonymous_questions(false),
question_text(""),
answer_text("") {}
Question::Question(std::string line) {
HelperFunction helper_function;
std::vector<std::string> fields = helper_function.split_string(line);
assert((int)fields.size() == 7);
question_id = helper_function.to_int(fields[0]);
parent_question_id = helper_function.to_int(fields[1]);
from_user_id = helper_function.to_int(fields[2]);
to_user_id = helper_function.to_int(fields[3]);
is_anonymous_questions = helper_function.to_int(fields[4]);
question_text = fields[5];
answer_text = fields[6];
}
std::string Question::to_string() const {
std::ostringstream oss;
oss << question_id << ',' << parent_question_id << ',' << from_user_id << ',' << to_user_id << ','
<< is_anonymous_questions << ',' << question_text << ',' << answer_text;
return oss.str();
}
void Question::print_to_question() const {
if (parent_question_id != -1)
std::cout << "\n\t\t > Thread: ";
std::cout << "Question Id[" << question_id << "] From User Id [" << from_user_id << "] : \n"
<< std::setw(25) << std::left << " > Question : " << question_text;
if (answer_text != "")
std::cout << '\n' << std::setw(25) << std::left << "\t > Answer : " << answer_text << '\n';
else
std::cout << '\n' << std::setw(25) << std::left << "\t > Not Answered Yet!\n";
std::cout << "--------------------------------------------------------------\n\n";
}
void Question::print_from_question() const {
std::cout << "\nQuestion Id [" << question_id << "] ";
if (!is_anonymous_questions)
std::cout << " !AQ ";
std::cout << " To User Id[" << to_user_id << "] : \n"
<< std::setw(25) << std::left << " > Question : " << question_text;
if (answer_text != "")
std::cout << '\n' << std::setw(25) << std::left << "\t > Answer : " << answer_text << '\n';
else
std::cout << '\n' << std::setw(25) << std::left << "\t > Not Answered Yet!\n";
std::cout << "--------------------------------------------------------------\n\n";
}
void Question::print_feed_question() const {
if (parent_question_id != -1)
std::cout << "\n\t\tThread Parent Question ID [" << parent_question_id << "] ";
std::cout << " Question Id [" << question_id << "] ";
if (!is_anonymous_questions)
std::cout << " From User Id[" << from_user_id << "]";
std::cout << " To User Id[" << to_user_id << "]\n"
<< std::setw(25) << std::left << "" << " > Question : " << question_text;
if (answer_text != "")
std::cout << '\n' << std::setw(25) << std::left << "\t > Answer : " << answer_text << '\n';
else
std::cout << '\n' << std::setw(25) << std::left << "\t > Not Answered Yet!\n";
std::cout << "--------------------------------------------------------------\n\n";
}
int Question::get_qusetion_id() const {
return question_id;
}
void Question::set_question_id(int& id) {
question_id = id;
}
int Question::get_parent_question_id() const {
return parent_question_id;
}
void Question::set_parent_question_id(int& id) {
parent_question_id = id;
}
int Question::get_from_user_id() const {
return from_user_id;
}
void Question::set_from_user_id(int& id) {
from_user_id = id;
}
int Question::get_to_user_id() const {
return to_user_id;
}
void Question::set_to_user_id(int& id) {
to_user_id = id;
}
int Question::get_is_anonymous_questions() const {
return is_anonymous_questions;
}
void Question::set_is_anonymous_questions(int& is_aq) {
is_anonymous_questions = is_aq;
}
std::string Question::get_question_text() const {
return question_text;
}
void Question::set_question_text(std::string& text) {
question_text = text;
}
std::string Question::get_answer_text() const {
return answer_text;
}
void Question::set_answer_text(std::string& text) {
answer_text = text;
}