|
@@ -14,7 +14,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
14
|
14
|
{
|
15
|
15
|
quadraticFormulaCheck();
|
16
|
16
|
|
17
|
|
-
|
18
|
17
|
ui->setupUi(this);
|
19
|
18
|
scene= new QGraphicsScene(this);
|
20
|
19
|
scene->setSceneRect(QRectF(QPointF(0,0), QPointF(0,0)));
|
|
@@ -32,15 +31,12 @@ MainWindow::MainWindow(QWidget *parent) :
|
32
|
31
|
ui->RunPushButton->move(10,385);
|
33
|
32
|
ui->retryButton->move(180,385);
|
34
|
33
|
|
35
|
|
-
|
36
|
|
-
|
37
|
34
|
frogger = new frog;
|
38
|
35
|
|
39
|
36
|
globalTimer = new QTimer;
|
40
|
37
|
scene->addWidget(frogger);
|
41
|
38
|
|
42
|
39
|
ui->RunPushButton->setEnabled(false);
|
43
|
|
-
|
44
|
40
|
}
|
45
|
41
|
|
46
|
42
|
|
|
@@ -50,26 +46,35 @@ MainWindow::~MainWindow()
|
50
|
46
|
delete scene;
|
51
|
47
|
}
|
52
|
48
|
|
|
49
|
+// This function validates if the results from the QuadraticPlus and QuadraticMinus
|
|
50
|
+// functions are correct. If they are not, then the program exits.
|
53
|
51
|
|
54
|
52
|
void MainWindow::quadraticFormulaCheck()
|
55
|
53
|
{
|
56
|
|
- // float firstX;
|
57
|
54
|
double resultFromFunction;
|
58
|
55
|
bool pass = true;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+ // The values and valuesForMinus arrays contain precomputed a, b, c, and y values
|
|
59
|
+ // for the quadratic equations. They are used for testing if the functions written by
|
|
60
|
+ // the student are correct.
|
|
61
|
+ // For example: if a = 357, b = -1000, c = 698, then y = 1.4804781099
|
|
62
|
+
|
59
|
63
|
double values[] = {357 , -1000 , 698 , 1.4804781099 , 748 , -392 , 51 , 0.28391805554 ,
|
60
|
|
- 689 , -689 , 172 , 0.519048482944 , 90 , 521 , 751 , -2.71178575308 , 5 , 107 ,
|
61
|
|
- 465 , -6.0642692054 , 1609 , -983 , 150 , 0.314734649792 , 273 , 496 , 224 ,
|
62
|
|
- -0.839700867988 , 2 , 91 , 920 , -15.1630045473 , 48 , 300 , 463 , -2.77889067238 ,
|
63
|
|
- 852 , 907 , 241 , -0.510947439149};
|
|
64
|
+ 689 , -689 , 172 , 0.519048482944 , 90 , 521 , 751 , -2.71178575308 , 5 , 107 ,
|
|
65
|
+ 465 , -6.0642692054 , 1609 , -983 , 150 , 0.314734649792 , 273 , 496 , 224 ,
|
|
66
|
+ -0.839700867988 , 2 , 91 , 920 , -15.1630045473 , 48 , 300 , 463 , -2.77889067238 ,
|
|
67
|
+ 852 , 907 , 241 , -0.510947439149};
|
64
|
68
|
|
65
|
69
|
double valuesForMinus[] = {129 , -486 , 456 , 1.76744186047 , 384 , 980 , 625 , -1.30208333333 ,
|
66
|
|
- 270 , -904 , 755 , 1.59515823795 , 67 , -450 , 752 , 3.12650485528 , 98 , 506 , 651 ,
|
67
|
|
- -2.72985550047 , 38 , -373 , 901 , 4.29396930804 , 273 , -282 , 72 , 0.461538461538 ,
|
68
|
|
- 225 , -889 , 874 , 1.84 , 8 , 136 , 522 , -11.1457513111 , 5 , 77 , 214 , -11.760788100};
|
|
70
|
+ 270 , -904 , 755 , 1.59515823795 , 67 , -450 , 752 , 3.12650485528 , 98 , 506 , 651 ,
|
|
71
|
+ -2.72985550047 , 38 , -373 , 901 , 4.29396930804 , 273 , -282 , 72 , 0.461538461538 ,
|
|
72
|
+ 225 , -889 , 874 , 1.84 , 8 , 136 , 522 , -11.1457513111 , 5 , 77 , 214 , -11.760788100};
|
69
|
73
|
|
70
|
74
|
double a, b, c, expected;
|
71
|
75
|
|
72
|
|
- //Verifying if the equation written by the student is correct
|
|
76
|
+ // Validate the QuadraticPlus function....
|
|
77
|
+
|
73
|
78
|
for (int i = 0; i < 40 && pass; i+=4){
|
74
|
79
|
a = values[i];
|
75
|
80
|
b = values[i+1];
|
|
@@ -77,17 +82,16 @@ void MainWindow::quadraticFormulaCheck()
|
77
|
82
|
expected = values[i+3];
|
78
|
83
|
|
79
|
84
|
resultFromFunction = frogger->QuadraticPlus(a,b,c);
|
80
|
|
-
|
81
|
|
- if( fabs(resultFromFunction - expected) > 0.00001) {
|
82
|
|
- pass = false;
|
83
|
|
- }
|
|
85
|
+ pass = ( fabs(resultFromFunction - expected) < 0.00001) ;
|
84
|
86
|
}
|
|
87
|
+
|
85
|
88
|
if(!pass){
|
86
|
89
|
QMessageBox::information(this, "Error", "La funcion cuadratica esta mal escrita!");
|
87
|
90
|
exit(1);
|
88
|
91
|
}
|
89
|
92
|
|
90
|
|
- //Verifying if the equation written by the student is correct
|
|
93
|
+ // Validate the QuadraticMinus function....
|
|
94
|
+
|
91
|
95
|
for (int i = 0; i < 40 && pass; i+=4){
|
92
|
96
|
a = valuesForMinus[i];
|
93
|
97
|
b = valuesForMinus[i+1];
|
|
@@ -95,97 +99,67 @@ void MainWindow::quadraticFormulaCheck()
|
95
|
99
|
expected = valuesForMinus[i+3];
|
96
|
100
|
|
97
|
101
|
resultFromFunction = frogger->QuadraticMinus(a,b,c);
|
98
|
|
-
|
99
|
|
- if( fabs(resultFromFunction - expected) > 0.00001) {
|
100
|
|
- pass = false;
|
101
|
|
- }
|
|
102
|
+ pass = ( fabs(resultFromFunction - expected) < 0.00001 );
|
102
|
103
|
}
|
|
104
|
+
|
103
|
105
|
if(!pass){
|
104
|
106
|
QMessageBox::information(this, "Error", "La funcion cuadratica esta mal escrita!");
|
105
|
107
|
exit(1);
|
106
|
108
|
}
|
107
|
109
|
}
|
108
|
110
|
|
109
|
|
-void MainWindow::on_RunPushButton_clicked()
|
110
|
|
-{
|
111
|
|
- int a = 0;
|
112
|
|
- int b = 0;
|
113
|
|
- int c = 0;
|
114
|
|
- int det = 0;
|
|
111
|
+void MainWindow::clearTheTextBoxes() {
|
|
112
|
+ ui->alineEdit->clear();
|
|
113
|
+ ui->blineEdit->clear();
|
|
114
|
+ ui->clineEdit->clear();
|
|
115
|
+}
|
|
116
|
+
|
|
117
|
+bool MainWindow::aTextBoxIsEmpty() {
|
|
118
|
+ return (ui->alineEdit->text().length() == 0 ||
|
|
119
|
+ ui->blineEdit->text().length() == 0 ||
|
|
120
|
+ ui->clineEdit->text().length() == 0);
|
|
121
|
+}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+void MainWindow::on_RunPushButton_clicked() {
|
|
125
|
+ int a = 0, b = 0, c = 0;
|
|
126
|
+ int det;
|
|
127
|
+
|
115
|
128
|
a = (ui->alineEdit->text().toInt());
|
116
|
129
|
b = (ui->blineEdit->text().toInt());
|
117
|
130
|
c = (ui->clineEdit->text().toInt());
|
118
|
131
|
|
119
|
132
|
det = (pow(b,2) - (4*a*c));
|
120
|
133
|
|
121
|
|
- if(a > 0){
|
|
134
|
+ if(a > 0)
|
122
|
135
|
QMessageBox::information(this, "Error", "La parabola abre hacia arriba y por lo tanto el sapo no brincara");
|
123
|
|
- ui->alineEdit->clear();
|
124
|
|
- ui->blineEdit->clear();
|
125
|
|
- ui->clineEdit->clear();
|
126
|
|
- }
|
127
|
|
- else if(a == 0){
|
|
136
|
+ else if(a == 0)
|
128
|
137
|
QMessageBox::information(this, "Error", "No hay parabola y por lo tanto el sapo no brincara");
|
129
|
|
- ui->alineEdit->clear();
|
130
|
|
- ui->blineEdit->clear();
|
131
|
|
- ui->clineEdit->clear();
|
132
|
|
- }
|
133
|
|
- else{
|
134
|
|
- if(det < 0){
|
|
138
|
+ else {
|
|
139
|
+ if(det < 0)
|
135
|
140
|
QMessageBox::information(this, "Error", "No tiene intercepto y por lo tanto el sapo no brincara");
|
136
|
|
- ui->alineEdit->clear();
|
137
|
|
- ui->blineEdit->clear();
|
138
|
|
- ui->clineEdit->clear();
|
139
|
|
- }
|
140
|
|
- else if(det == 0){
|
|
141
|
+ else if(det == 0)
|
141
|
142
|
QMessageBox::information(this, "Error", "El vertice esta en el intercepto y por lo tanto el sapo no brincara");
|
142
|
|
- ui->alineEdit->clear();
|
143
|
|
- ui->blineEdit->clear();
|
144
|
|
- ui->clineEdit->clear();
|
145
|
|
- }
|
146
|
143
|
else{
|
147
|
144
|
frogger->run(a, b, c);
|
148
|
145
|
ui->RunPushButton->setEnabled(false);
|
149
|
|
- ui->alineEdit->clear();
|
150
|
|
- ui->blineEdit->clear();
|
151
|
|
- ui->clineEdit->clear();
|
152
|
146
|
}
|
153
|
147
|
}
|
154
|
|
-
|
155
|
|
-
|
|
148
|
+ clearTheTextBoxes();
|
156
|
149
|
}
|
157
|
150
|
|
158
|
|
-void MainWindow::on_retryButton_clicked()
|
159
|
|
-{
|
|
151
|
+void MainWindow::on_retryButton_clicked() {
|
160
|
152
|
frogger->reset();
|
161
|
153
|
}
|
162
|
154
|
|
163
|
|
-void MainWindow::on_alineEdit_textChanged(const QString &)
|
164
|
|
-{
|
165
|
|
- if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
|
166
|
|
- ui->RunPushButton->setEnabled(true);
|
167
|
|
- }
|
168
|
|
- else{
|
169
|
|
- ui->RunPushButton->setEnabled(false);
|
170
|
|
- }
|
|
155
|
+void MainWindow::on_alineEdit_textChanged(const QString &) {
|
|
156
|
+ ui->RunPushButton->setEnabled(!aTextBoxIsEmpty());
|
171
|
157
|
}
|
172
|
158
|
|
173
|
|
-void MainWindow::on_blineEdit_textChanged(const QString &)
|
174
|
|
-{
|
175
|
|
- if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
|
176
|
|
- ui->RunPushButton->setEnabled(true);
|
177
|
|
- }
|
178
|
|
- else{
|
179
|
|
- ui->RunPushButton->setEnabled(false);
|
180
|
|
- }
|
|
159
|
+void MainWindow::on_blineEdit_textChanged(const QString &) {
|
|
160
|
+ ui->RunPushButton->setEnabled(!aTextBoxIsEmpty());
|
181
|
161
|
}
|
182
|
162
|
|
183
|
|
-void MainWindow::on_clineEdit_textChanged(const QString &)
|
184
|
|
-{
|
185
|
|
- if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
|
186
|
|
- ui->RunPushButton->setEnabled(true);
|
187
|
|
- }
|
188
|
|
- else{
|
189
|
|
- ui->RunPushButton->setEnabled(false);
|
190
|
|
- }
|
|
163
|
+void MainWindow::on_clineEdit_textChanged(const QString &) {
|
|
164
|
+ ui->RunPushButton->setEnabled(!aTextBoxIsEmpty());
|
191
|
165
|
}
|