No Description

functions.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QDebug>
  4. #include <QString>
  5. #include <cstdlib>
  6. #include <QMessageBox>
  7. #include <QMap>
  8. #include "functions.h"
  9. #ifdef _WIN32
  10. #include <windows.h>
  11. #else
  12. #include <unistd.h>
  13. #endif
  14. // =========================================================
  15. // Sort Functions
  16. // =========================================================
  17. bool validateSorts(const QString &a, const QString &b, const QString &c) {
  18. return (a.length() * b.length() * c.length() > 0);
  19. }
  20. void mySortAlpha(QString &a, QString &b, QString &c) {
  21. if (a > b ) {
  22. if (c > a) swap(b,c);
  23. else if (b > c) swap(a,b);
  24. else {
  25. QString tmp = a;
  26. a = b; b = c; c = tmp;
  27. }
  28. }
  29. else {
  30. if (a > c) {
  31. QString tmp = c;
  32. c = b; b = a; a = tmp;
  33. }
  34. else if (b > c) swap(b,c);
  35. else {
  36. // they are already in order :-)
  37. }
  38. }
  39. }
  40. void mySortBeta(QString &a, QString &b, QString &c) {
  41. if (a > b ) {
  42. if (c > a) swap(a,b);
  43. else if (b > c) swap(a,c);
  44. else {
  45. QString tmp = a;
  46. a = b; b = c; c = tmp;
  47. }
  48. }
  49. else {
  50. if (a > c) {
  51. QString tmp = c;
  52. c = b; b = a; a = tmp;
  53. }
  54. else if (b > c) swap(b,c);
  55. else {
  56. // they are already in order :-)
  57. }
  58. }
  59. }
  60. void mySortGamma(QString &a, QString &b, QString &c) {
  61. if (a > b ) {
  62. if (c > a) swap(a,b);
  63. else if (b > c) swap(a,c);
  64. else {
  65. QString tmp = a;
  66. a = c; c = b; b = tmp;
  67. }
  68. }
  69. else {
  70. if (a > c) {
  71. QString tmp = c;
  72. c = b; b = a; a = tmp;
  73. }
  74. else if (b > c) swap(b,c);
  75. else {
  76. // they are already in order :-)
  77. }
  78. }
  79. }
  80. void mySortDelta(QString &a, QString &b, QString &c) {
  81. if (a < b ) {
  82. if (c < a) swap(a,b);
  83. else if (b < c) swap(a,c);
  84. else {
  85. QString tmp = a;
  86. a = b; b = c; c = tmp;
  87. }
  88. }
  89. else {
  90. if (a > c) {
  91. QString tmp = c;
  92. c = b; b = a; a = tmp;
  93. }
  94. else if (b > c) swap(b,c);
  95. else {
  96. // they are already in order :-)
  97. }
  98. }
  99. }
  100. //This is the correct dice roller
  101. void MainWindow::diceAlpha(){
  102. QString a, b;
  103. //This loop is used to simulate the dice rolling by
  104. //changing the images at a slowing down speed
  105. for (int i = 0; i<=150000 ; i=i+5000){
  106. Sleep(i);
  107. //First dice image. Since we want random pictures
  108. //on each iteration, we get a random number, converted
  109. //it to string and append it to others string that
  110. //conform the names of the dices
  111. a = ":/images/resources/d";
  112. a.append(QString::number(rand()%6 + 1));
  113. a.append(".png");
  114. b = ":/images/resources/d";
  115. b.append(QString::number(rand()%6 + 1));
  116. b.append(".png");
  117. //We load the images and check if there is no problem with them
  118. if(!dice1.load(a) || !dice2.load(b)){
  119. qDebug() << "Error2 Loading image";
  120. }
  121. //Finally we set the labels with the random dice images
  122. label[3]->setPixmap(QPixmap::fromImage(dice1));
  123. label[4]->setPixmap(QPixmap::fromImage(dice2));
  124. // Is there an option to see the changes of the dice/label
  125. // in this function and no just when we get out of it?
  126. // Fail attempts
  127. // layout->update();
  128. // repaint();
  129. // window->repaint();
  130. // label[3]->repaint();
  131. // label[3]->update();
  132. // label[3]->hide();
  133. // label[3]->show();
  134. // label[3]->setVisible(false);
  135. // label[3]->setVisible(true);
  136. // layout->update();
  137. // update();
  138. // window->update();
  139. window->hide();
  140. window->show();
  141. }
  142. //Finally, we set the result of the sum of the dices.
  143. QString a2 = (QString)a[20];
  144. QString b2 = (QString)b[20];
  145. int total = a2.toInt() + b2.toInt();
  146. line[0]->setText(QString::number(total));
  147. }
  148. //This version sums the first dice twice
  149. void MainWindow::diceBeta(){
  150. QString a, b;
  151. for (int i = 0; i<=150000 ; i=i+5000){
  152. Sleep(i);
  153. a = ":/images/resources/d";
  154. a.append(QString::number(rand()%6 + 1));
  155. a.append(".png");
  156. b = ":/images/resources/d";
  157. b.append(QString::number(rand()%6 + 1));
  158. b.append(".png");
  159. if(!dice1.load(a) || !dice2.load(b)){
  160. qDebug() << "Error2 Loading image";
  161. }
  162. label[3]->setPixmap(QPixmap::fromImage(dice1));
  163. label[4]->setPixmap(QPixmap::fromImage(dice2));
  164. // Is there an option to see the changes of the dice/label
  165. // in this function and no just when we get out of it?
  166. window->hide();
  167. window->show();
  168. }
  169. int total = a[20].digitValue() + a[20].digitValue();
  170. line[0]->setText(QString::number(total));
  171. }
  172. //This one substracts the second dice to the first one
  173. void MainWindow::diceGamma(){
  174. QString a, b;
  175. for (int i = 0; i<=150000 ; i=i+5000){
  176. Sleep(i);
  177. a = ":/images/resources/d";
  178. a.append(QString::number(rand()%6 + 1));
  179. a.append(".png");
  180. b = ":/images/resources/d";
  181. b.append(QString::number(rand()%6 + 1));
  182. b.append(".png");
  183. if(!dice1.load(a) || !dice2.load(b)){
  184. qDebug() << "Error2 Loading image";
  185. }
  186. label[3]->setPixmap(QPixmap::fromImage(dice1));
  187. label[4]->setPixmap(QPixmap::fromImage(dice2));
  188. // Is there an option to see the changes of the dice/label
  189. // in this function and no just when we get out of it?
  190. window->hide();
  191. window->show();
  192. }
  193. QString a2 = (QString)a[20];
  194. QString b2 = (QString)b[20];
  195. int total = a2.toInt() - b2.toInt();
  196. line[0]->setText(QString::number(total));
  197. }
  198. //This one tooks the number 6 as a 12
  199. void MainWindow::diceDelta(){
  200. QString a, b;
  201. for (int i = 0; i<=150000 ; i=i+5000){
  202. Sleep(i);
  203. a = ":/images/resources/d";
  204. a.append(QString::number(rand()%6 + 1));
  205. a.append(".png");
  206. b = ":/images/resources/d";
  207. b.append(QString::number(rand()%6 + 1));
  208. b.append(".png");
  209. if(!dice1.load(a) || !dice2.load(b)){
  210. qDebug() << "Error2 Loading image";
  211. }
  212. label[3]->setPixmap(QPixmap::fromImage(dice1));
  213. label[4]->setPixmap(QPixmap::fromImage(dice2));
  214. // Is there an option to see the changes of the dice/label
  215. // in this function and no just when we get out of it?
  216. window->hide();
  217. window->show();
  218. }
  219. int x, y;
  220. QString a2 = (QString)a[20];
  221. QString b2 = (QString)b[20];
  222. if (a2.toInt() == 6){
  223. x = 12;
  224. }
  225. else{
  226. x = a2.toInt();
  227. }
  228. if (b2.toInt() == 6){
  229. y = 12;
  230. }
  231. else{
  232. y = b2.toInt();
  233. }
  234. int total = x + y;
  235. line[0]->setText(QString::number(total));
  236. }
  237. // =========================================================
  238. // Rock Paper Scissor Functions
  239. // =========================================================
  240. ///
  241. /// \brief RPSAlpha
  242. /// \param p1
  243. /// \param p2
  244. /// \param score1
  245. /// \param score2
  246. /// \return
  247. ///
  248. int RPSAlpha(char p1, char p2, int &score1, int &score2) {
  249. p1 = toupper(p1);
  250. p2 = toupper(p2);
  251. if ( p1 == 'P' ) {
  252. if ( p2 == 'P' ) return 0;
  253. else if (p2 == 'R') {
  254. score1++; return 1;
  255. }
  256. else {
  257. score2++; return 2;
  258. }
  259. }
  260. else if (p1 == 'R') {
  261. if ( p2 == 'R' ) return 0;
  262. else if (p2 == 'S') {
  263. score1++; return 1;
  264. }
  265. else {
  266. score2++; return 2;
  267. }
  268. }
  269. else {
  270. if ( p2 == 'S' ) return 0;
  271. else if (p2 == 'P') {
  272. score1++; return 1;
  273. }
  274. else {
  275. score2++; return 2;
  276. }
  277. }
  278. }
  279. ///
  280. /// \brief RPSBeta
  281. /// \param p1
  282. /// \param p2
  283. /// \param score1
  284. /// \param score2
  285. /// \return
  286. ///
  287. int RPSBeta(char p1, char p2, int &score1, int &score2) {
  288. p1 = toupper(p1);
  289. p2 = toupper(p2);
  290. if ( p1 == 'P' ) {
  291. if ( p2 == 'S' ) return 0;
  292. else if (p2 == 'R') {
  293. score1++; return 1;
  294. }
  295. else {
  296. score2++; return 2;
  297. }
  298. }
  299. else if (p1 == 'R') {
  300. if ( p2 == 'S' ) return 0;
  301. else if (p2 == 'P') {
  302. score1++; return 1;
  303. }
  304. else {
  305. score2++; return 2;
  306. }
  307. }
  308. else {
  309. if ( p2 == 'S' ) return 0;
  310. else if (p2 == 'R') {
  311. score1++; return 1;
  312. }
  313. else {
  314. score2++; return 2;
  315. }
  316. }
  317. }
  318. ///
  319. /// \brief RPSGamma
  320. /// \param p1
  321. /// \param p2
  322. /// \param score1
  323. /// \param score2
  324. /// \return
  325. ///
  326. int RPSGamma(char p1, char p2, int &score1, int &score2) {
  327. p1 = toupper(p1);
  328. p2 = toupper(p2);
  329. if ( p1 == 'P' ) {
  330. if ( p2 == 'P' ) return 0;
  331. else if (p2 == 'S') {
  332. score1++; return 1;
  333. }
  334. else {
  335. score2++; return 2;
  336. }
  337. }
  338. else if (p1 == 'R') {
  339. if ( p2 == 'R' ) return 0;
  340. else if (p2 == 'P') {
  341. score1++; return 1;
  342. }
  343. else {
  344. score2++; return 2;
  345. }
  346. }
  347. else {
  348. if ( p2 == 'P' ) return 0;
  349. else if (p2 == 'S') {
  350. score1++; return 1;
  351. }
  352. else {
  353. score2++; return 2;
  354. }
  355. }
  356. }
  357. ///
  358. /// \brief RPSDelta
  359. /// \param p1
  360. /// \param p2
  361. /// \param score1
  362. /// \param score2
  363. /// \return
  364. ///
  365. int RPSDelta(char p1, char p2, int &score1, int &score2) {
  366. p1 = toupper(p1);
  367. p2 = toupper(p2);
  368. if ( p1 == 'P' ) {
  369. if ( p2 == 'P' ) return 0;
  370. else if (p2 == 'S') {
  371. score2++; return 1;
  372. }
  373. else {
  374. score1++; return 2;
  375. }
  376. }
  377. else if (p1 == 'R') {
  378. if ( p2 == 'R' ) return 0;
  379. else if (p2 == 'P') {
  380. score2++; return 1;
  381. }
  382. else {
  383. score1++; return 2;
  384. }
  385. }
  386. else {
  387. if ( p2 == 'P' ) return 0;
  388. else if (p2 == 'S') {
  389. score2++; return 1;
  390. }
  391. else {
  392. score1++; return 2;
  393. }
  394. }
  395. }
  396. // =========================================================
  397. // Check Words Functions
  398. // =========================================================
  399. QMap<int,QString> M;
  400. ///
  401. /// \brief initCheckWMaps: initialize the values in the dictionary that is used throughout
  402. /// the check functions.
  403. ///
  404. void initCheckWMaps() {
  405. M[1] = "one"; M[2] = "two"; M[3] = "three"; M[4] = "four";
  406. M[5] = "five"; M[6] = "six";
  407. M[7] = "seven"; M[8] = "eight"; M[9] = "nine"; M[10] = "ten";
  408. M[11] = "eleven"; M[12] = "twelve"; M[13] = "thirteen"; M[14] = "fourteen";
  409. M[15] = "fifteen"; M[16] = "sixteen"; M[17] = "seventeen"; M[18] = "eighteen";
  410. M[19] = "nineteen";
  411. M[20] = "twenty"; M[30] = "thirty"; M[40] = "fourty"; M[50] = "fifty";
  412. M[60] = "sixty"; M[70] = "seventy"; M[80] = "eighty"; M[90] = "ninety";
  413. }
  414. ///
  415. /// \brief validateCheckQty: determines is entered text is a valid number in [0,999999999]
  416. /// \param st text entered by the user
  417. /// \param qty text converted to integer
  418. /// \return true if the entered text is valid
  419. ///
  420. bool validateCheckQty(QString st, unsigned int &qty) {
  421. int i = 0;
  422. for (i = 0; i < st.length() ; i++) {
  423. if (!st[i].isDigit()) return false;
  424. }
  425. if (i > 9) return false;
  426. qty = st.toInt();
  427. return true;
  428. }
  429. ///
  430. /// \brief wordForNumber: Given a number n in [0,999] returns the word equivalent
  431. /// \param n: the number
  432. /// \return a Qstring containing the number in words
  433. ///
  434. QString wordForNumber(int n) {
  435. QString st;
  436. int tens = n % 100;
  437. if (tens == 0)
  438. st = "";
  439. else if (tens <= 20)
  440. st = M[n];
  441. else {
  442. st = M[10 * (tens/10)];
  443. if (tens % 10)
  444. st.append(" " + M[tens % 10]);
  445. }
  446. n = n / 100;
  447. if (n) st.prepend(M[n % 10] + " hundred" + (st.length() > 0 ? " " : ""));
  448. return st;
  449. }
  450. ///
  451. /// \brief checkWAlpha: One of the functions to convert a number in [0,999999999] to words
  452. /// \param n: the number
  453. /// \return a Qstring containing the number in words
  454. ///
  455. QString checkWAlpha(int n) {
  456. QString st;
  457. // the cents
  458. st = wordForNumber(n % 1000);
  459. // the thousands
  460. n = n / 1000;
  461. if (n % 1000) st.prepend( wordForNumber(n % 1000) + " thousand" + (st.length() > 0 ? " " : ""));
  462. // the millions
  463. n = n / 1000;
  464. if (n % 1000) st.prepend( wordForNumber(n % 1000) + " million" + (st.length() > 0 ? " " : ""));
  465. return st;
  466. }
  467. ///
  468. /// \brief checkWBeta: One of the functions to convert a number in [0,999999999] to words
  469. /// \param n: the number
  470. /// \return a Qstring containing the number in words
  471. ///
  472. QString checkWBeta(int n) {
  473. QString st;
  474. st = wordForNumber(n % 1000);
  475. n = n / 1000;
  476. if (n % 1000) st.append( wordForNumber(n % 1000) + " thousand" + (st.length() > 0 ? " " : ""));
  477. n = n / 1000;
  478. if (n % 1000) st.append( wordForNumber(n % 1000) + " million" + (st.length() > 0 ? " " : ""));
  479. return st;
  480. }
  481. ///
  482. /// \brief checkWGamma: One of the functions to convert a number in [0,999999999] to words
  483. /// \param n: the number
  484. /// \return a Qstring containing the number in words
  485. ///
  486. QString checkWGamma(int n) {
  487. QString st;
  488. st = wordForNumber(n % 10);
  489. n = n / 1000;
  490. if (n % 1000) st.append( wordForNumber(n % 10) + " thousand" + (st.length() > 0 ? " " : ""));
  491. n = n / 1000;
  492. if (n % 1000) st.append( wordForNumber(n % 10) + " million" + (st.length() > 0 ? " " : ""));
  493. return st;
  494. }
  495. ///
  496. /// \brief checkWDelta: One of the functions to convert a number in [0,999999999] to words
  497. /// \param n: the number
  498. /// \return a Qstring containing the number in words
  499. ///
  500. QString checkWDelta(int n) {
  501. QString st;
  502. n /= 10;
  503. st = wordForNumber(n % 1000);
  504. n = n / 1000;
  505. if (n % 1000) st.prepend( wordForNumber(n % 1000) + " thousand" + (st.length() > 0 ? " " : ""));
  506. n = n / 1000;
  507. if (n % 1000) st.prepend( wordForNumber(n % 1000) + " million" + (st.length() > 0 ? " " : ""));
  508. return st;
  509. }
  510. // =========================================================
  511. // Zulu Functions
  512. // =========================================================
  513. bool validZuluTime(const QString &time, const QString &zone, int &hours, int &minutes) {
  514. int i = 0;
  515. for (i = 0; i< time.size(); i++)
  516. if (!time[i].isDigit()) return false;
  517. if (i != 4) return false;
  518. hours = time.mid(0,2).toInt();
  519. minutes = time.mid(2,2).toInt();
  520. if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)
  521. return false;
  522. if (zone.length() < 1 || !zone[0].isLetter() || toupper(zone.toStdString()[0]) == 'J') return false;
  523. return true;
  524. }
  525. //This is the correct one
  526. QString zuluAlpha(int hours, int minutes, char zone) {
  527. int diff = 0;
  528. if (zone <= 'I') diff = zone - 'A' + 1;
  529. else if (zone <= 'M') diff = 10 + (zone - 'K');
  530. else if (zone <= 'Y') diff = -(zone - 'N' + 1);
  531. else diff = 0;
  532. hours = (hours + (24 + diff) ) % 24;
  533. return QString::number(hours) + QString::number(minutes);
  534. }
  535. QString zuluBeta(int hours, int minutes, char zone) {
  536. int diff = 0;
  537. if (zone <= 'I') diff = zone - 'B' + 1;
  538. else if (zone <= 'M') diff = 10 + (zone - 'M');
  539. else if (zone <= 'Y') diff = -(zone - 'N');
  540. diff = 0;
  541. hours = (hours + (24 + diff) ) % 24;
  542. return QString::number(hours) + QString::number(minutes);
  543. }
  544. QString zuluGamma(int hours, int minutes, char zone) {
  545. int diff = 0;
  546. if (zone <= 'I') diff = zone - 'A' + 1;
  547. else if (zone <= 'M') diff = 10 + (zone - 'M');
  548. else if (zone <= 'Y') diff = -(zone - 'N');
  549. else diff = 0;
  550. hours = (hours + (24 - diff) ) % 24;
  551. return QString::number(hours) + QString::number(minutes);
  552. }
  553. QString zuluDelta(int hours, int minutes, char zone) {
  554. int diff = 0;
  555. if (zone <= 'M') diff = zone - 'B' + 1;
  556. else if (zone <= 'Y') diff = -(zone - 'N');
  557. else diff = 0;
  558. hours = (hours + (24 - diff) ) % 24;
  559. return QString::number(hours) + QString::number(minutes);
  560. }
  561. // =========================================================
  562. // APFT Functions
  563. // =========================================================
  564. //This it the correct one
  565. void MainWindow::APFTAlpha(){
  566. //For each one of these variables we apply the formula that they use
  567. //to set the points
  568. double sit_ups = qFloor(line[0]->text().toDouble() * 1.6 - 24.8);
  569. double push_ups = qFloor(line[1]->text().toInt() * 1.42);
  570. double running_time = qFloor((line[2]->text().left(2).append('.' + line[2]->text().right(2))).toDouble());
  571. double two_mile_run = qFloor((820 / 3) - ((40 * running_time) / 3));
  572. //Since the maximum of points that one can obtain
  573. //on each excercise type is 100, we restrict it
  574. if (sit_ups > 100){
  575. sit_ups = 100;
  576. }
  577. else if (sit_ups < 0){
  578. sit_ups = 0;
  579. }
  580. if (push_ups > 100){
  581. push_ups = 100;
  582. }
  583. else if (push_ups < 0){
  584. push_ups = 0;
  585. }
  586. if (two_mile_run > 100){
  587. two_mile_run = 100;
  588. }
  589. else if (two_mile_run < 0){
  590. two_mile_run = 0;
  591. }
  592. //Finally we set the outputs.
  593. line[3]->setText(QString::number(sit_ups));
  594. line[4]->setText(QString::number(push_ups));
  595. line[5]->setText(QString::number(two_mile_run));
  596. line[6]->setText(QString::number(push_ups + sit_ups + two_mile_run));
  597. if (push_ups >= 60 && sit_ups >= 60 && two_mile_run >= 60){
  598. label[7]->setText("PASS");
  599. }
  600. else{
  601. label[7]->setText("FAIL");
  602. }
  603. }
  604. //This one do not check if the number is greater than 100
  605. void MainWindow::APFTBeta(){
  606. double sit_ups = qFloor(line[0]->text().toDouble() * 1.6 - 24.8);
  607. double push_ups = qFloor(line[1]->text().toInt() * 1.42);
  608. double running_time = qFloor((line[2]->text().left(2).append('.' + line[2]->text().right(2))).toDouble());
  609. double two_mile_run = qFloor((820 / 3) - ((40 * running_time) / 3));
  610. line[3]->setText(QString::number(sit_ups));
  611. line[4]->setText(QString::number(push_ups));
  612. line[5]->setText(QString::number(two_mile_run));
  613. line[6]->setText(QString::number(push_ups + sit_ups + two_mile_run));
  614. if (push_ups >= 60 && sit_ups >= 60 && two_mile_run >= 60){
  615. line[7]->setText("PASS");
  616. }
  617. else{
  618. line[7]->setText("FAIL");
  619. }
  620. }
  621. //This one switch the results
  622. void MainWindow::APFTGamma(){
  623. double sit_ups = qFloor(line[0]->text().toDouble() * 1.6 - 24.8);
  624. double push_ups = qFloor(line[1]->text().toInt() * 1.42);
  625. double running_time = qFloor((line[2]->text().left(2).append('.' + line[2]->text().right(2))).toDouble());
  626. double two_mile_run = qFloor((820 / 3) - ((40 * running_time) / 3));
  627. if (sit_ups > 100){
  628. sit_ups = 100;
  629. }
  630. else if (sit_ups < 0){
  631. sit_ups = 0;
  632. }
  633. if (push_ups > 100){
  634. push_ups = 100;
  635. }
  636. else if (push_ups < 0){
  637. push_ups = 0;
  638. }
  639. if (two_mile_run > 100){
  640. two_mile_run = 100;
  641. }
  642. else if (two_mile_run < 0){
  643. two_mile_run = 0;
  644. }
  645. line[5]->setText(QString::number(sit_ups));
  646. line[3]->setText(QString::number(push_ups));
  647. line[4]->setText(QString::number(two_mile_run));
  648. line[6]->setText(QString::number(push_ups + sit_ups + two_mile_run));
  649. if (push_ups >= 60 && sit_ups >= 60 && two_mile_run >= 60){
  650. line[7]->setText("PASS");
  651. }
  652. else{
  653. line[7]->setText("FAIL");
  654. }
  655. }
  656. //This one do not sums the points but the quantities of each excercise
  657. void MainWindow::APFTDelta(){
  658. double sit_ups = qFloor(line[0]->text().toDouble() * 1.6 - 24.8);
  659. double push_ups = qFloor(line[1]->text().toInt() * 1.42);
  660. double running_time = qFloor((line[2]->text().left(2).append('.'
  661. + line[2]->text().right(2))).toDouble());
  662. double two_mile_run = qFloor((820 / 3) - ((40 * running_time) / 3));
  663. if (sit_ups > 100){
  664. sit_ups = 100;
  665. }
  666. else if (sit_ups < 0){
  667. sit_ups = 0;
  668. }
  669. if (push_ups > 100){
  670. push_ups = 100;
  671. }
  672. else if (push_ups < 0){
  673. push_ups = 0;
  674. }
  675. if (two_mile_run > 100){
  676. two_mile_run = 100;
  677. }
  678. else if (two_mile_run < 0){
  679. two_mile_run = 0;
  680. }
  681. int sumaTo = line[0]->text().toInt() + line[1]->text().toInt() + running_time;
  682. line[3]->setText(QString::number(sit_ups));
  683. line[4]->setText(QString::number(push_ups));
  684. line[5]->setText(QString::number(two_mile_run));
  685. line[6]->setText(QString::number(sumaTo));
  686. if (push_ups >= 60 && sit_ups >= 60 && two_mile_run >= 60){
  687. line[7]->setText("PASS");
  688. }
  689. else{
  690. line[7]->setText("FAIL");
  691. }
  692. }