-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise.cpp
More file actions
132 lines (112 loc) · 3.46 KB
/
Copy pathexercise.cpp
File metadata and controls
132 lines (112 loc) · 3.46 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
#include "exercise.h"
#include "ui_exercise.h"
#include"model_choose.h"
#include"user_info.h"
#include<QButtonGroup>
#include<QMessageBox>
#include<QList>
#include<QRandomGenerator>
#include<QChar>
#include<QDebug>
int exerflag;
extern QList<question>questionlist;
question temp_que;
QButtonGroup*box;
Exercise::Exercise(QWidget *parent) :
QDialog(parent),
ui(new Ui::Exercise)
{
if(exerflag==1){
QMessageBox msgBox;
msgBox.setWindowTitle("练习说明");
msgBox.setText("练习时选择左下角选项,点击确定则提交答案,系统判定正误,如果错误则告知答案\n"
"如需退出点击\"结束练习\"按钮");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
ui->setupUi(this);
this->setWindowTitle("练习模式");
ui->A->setChecked(false);
ui->B->setChecked(false);
ui->C->setChecked(false);
box=new QButtonGroup;
box->setExclusive(true);
box->addButton(ui->A);
box->addButton(ui->B);
box->addButton(ui->C);
int prnum=QRandomGenerator::global()->bounded(199);
temp_que=questionlist[prnum];
ui->textBrowser->setText("\n"+temp_que.quest+"\n\n\n"+temp_que.option);
}
Exercise::~Exercise()
{
delete ui;
}
void Exercise::on_return_2_clicked()
{
this->close();
Model_Choose*pic=new Model_Choose();
pic->show();
}
void Exercise::on_certain_clicked()
{
QChar ans;
if(!ui->A->isChecked()&&!ui->B->isChecked()&&!ui->C->isChecked()){
QMessageBox::critical(this,tr("警告"),tr("您需要选出选项再进行下一题"));
return;
}
if(ui->A->isChecked())ans='A';
if(ui->B->isChecked())ans='B';
if(ui->C->isChecked())ans='C';
qDebug()<<ans;
if(ans==temp_que.answer){
QMessageBox msgBox;
msgBox.setText("您答对了!是否进行下一题?");
msgBox.setStandardButtons(QMessageBox::Ok|QMessageBox::No);
int ret=msgBox.exec();
switch(ret){
case QMessageBox::Ok:{
int prnum=QRandomGenerator::global()->bounded(199);
temp_que=questionlist[prnum];
ui->textBrowser->setText("\n"+temp_que.quest+"\n\n\n"+temp_que.option);
box->setExclusive(false);
ui->A->setChecked(false);
ui->B->setChecked(false);
ui->C->setChecked(false);
box->setExclusive(true);
break;
}
case QMessageBox::No:{
this->close();
Model_Choose*pic=new Model_Choose();
pic->show();
break;
}
}
}
else{
QMessageBox msgBox;
msgBox.setText("您答错了!正确答案是:"+QString(temp_que.answer)+"\n是否进行下一题?");
msgBox.setStandardButtons(QMessageBox::Ok|QMessageBox::No);
int ret=msgBox.exec();
switch(ret){
case QMessageBox::Ok:{
int prnum=QRandomGenerator::global()->bounded(199);
temp_que=questionlist[prnum];
ui->textBrowser->setText("\n"+temp_que.quest+"\n\n\n"+temp_que.option);
box->setExclusive(false);
ui->A->setChecked(false);
ui->B->setChecked(false);
ui->C->setChecked(false);
box->setExclusive(true);
break;
}
case QMessageBox::No:{
this->close();
Model_Choose*pic=new Model_Choose();
pic->show();
break;
}
}
}
}