설명 없음

functions.cpp 21KB

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