暫無描述

functions.cpp 21KB

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