-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion.cpp
More file actions
132 lines (117 loc) · 3.9 KB
/
Copy pathQuestion.cpp
File metadata and controls
132 lines (117 loc) · 3.9 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
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
#include"Header.hpp"
Question::Question(){
cout<<"\e[1;35mChoose type of Question :(enter the number)"<<endl<<"1_Short Answer"<<endl<<"2_Test"<<endl<<"3_Long Answer\033[0m"<<endl;
int type; cin>>type; cin.ignore();
if(type == 1){
this->type="Short";
cout<<"Question body: ";
string tmp; getline(cin,tmp);
this->question_body=tmp;
cout<<"Answer : ";
getline(cin,tmp);
this->Answer=tmp;
cout<<"\e[0;32mCorrect answer score : \033[0m";
double pos; cin>>pos; cin.ignore();
cout<<"\033[31mWrong answer effect : \033[0m";
double neg; cin>>neg; cin.ignore();
this->Positive_effect=pos;
this->Negative_effect=neg;
for(int i=0;i<4;i++){
this->Options[i]="---this Question is not a test---";
}
}
else if(type == 2){
this->type="Test";
cout<<"Question body: ";
string tmp; getline(cin,tmp);
this->question_body=tmp;
cout<<"Enter the options :(4 choices for student)"<<endl;
for(int i=0;i<4;i++){
cout<<i+1<<"_";
string ans;
getline(cin,ans);
this->Options[i]=ans;
}
cout<<"Answer : ";
getline(cin,tmp);
this->Answer=tmp;
cout<<"\e[0;32mCorrect answer score : \033[0m";
double pos; cin>>pos; cin.ignore();
cout<<"\033[31mWrong answer effect : \033[0m";
double neg; cin>>neg; cin.ignore();
this->Positive_effect=pos;
this->Negative_effect=neg;
}
else if(type == 3){
this->type="Long";
cout<<"Question body: ";
string tmp; getline(cin,tmp);
this->question_body=tmp;
cout<<"Answer : ";
getline(cin,tmp);
this->Answer=tmp;
for(int i=0;i<4;i++){
this->Options[i]="---this Question is not a test---";
}
cout<<"\e[0;32mCorrect answer score : \033[0m";
double pos; cin>>pos; cin.ignore();
this->Positive_effect=pos;
this->Negative_effect=0;
}
}
void Question::display_to_teacher(){
if(this->type=="Short"){
cout<<this->question_body<<endl;
cout<<"Answer = "<<this->Answer<<endl;
cout<<"\e[0;32mCorrect answer score : \033[0m" <<this->Positive_effect<<endl;
cout<<"\033[31mWrong answer effect : \033[0m"<<this->Negative_effect<<endl;
return;
}
else if(this->type=="Test"){
cout<<this->question_body<<endl;
cout<<"Student options :"<<endl;
for(int i=0;i<4;i++){
if(this->Options[i]==Answer){
cout<<i+1<<"_\e[0;32m"<<Options[i]<<"\033[0m"<<endl;
}
else{
cout<<i+1<<"_\033[31m"<<Options[i]<<"\033[0m"<<endl;
}
}
cout<<"\e[0;32mCorrect answer score : \033[0m" <<this->Positive_effect<<endl;
cout<<"\033[31mWrong answer effect : \033[0m"<<this->Negative_effect<<endl;
return;
}
else if(this->type=="Long"){
cout<<question_body<<endl;
cout<<"Answer = "<<Answer<<endl;
return;
}
}
void Question::display_to_student(){
if(this->type=="Short"){
cout<<this->question_body<<endl;
return;
}
else if(this->type=="Test"){
cout<<this->question_body<<endl;
return;
}
else if(this->type=="Long"){
cout<<question_body<<endl;
return;
}
}
json Question::Question_to_json(){
json j_question;
j_question["type"] = this->type;
j_question["question_body"] = this->question_body;
j_question["Options"] = json :: array();
for(int i=0;i<4;i++){
j_question["Options"].push_back(this->Options[i]);
}
j_question["Answer"] = this->Answer;
j_question["Positive_effect"] = this -> Positive_effect;
j_question["Negative_effect"] = this-> Negative_effect;
return j_question;
}