Brak opisu

functions.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. #ifndef FUNCTIONS_H
  2. #define FUNCTIONS_H
  3. #include <string>
  4. using namespace std;
  5. /// \fn validateSorts
  6. /// \~English
  7. /// \brief Function to validate that sort is invoked with non-empty strings
  8. /// \param a first QSring
  9. /// \param b second Qstring
  10. /// \param c third QString
  11. /// \return true if non of the QStrings are empty
  12. /// \~Spanish
  13. /// \brief Valida que los QStrings que se van a ordenar no estén vacios.
  14. /// \param a primer QSring
  15. /// \param b segundo Qstring
  16. /// \param c tercer QString
  17. /// \return true si ninguno de los QString está vacio
  18. bool validateSorts(const QString &a, const QString &b, const QString &c);
  19. /// \fn mySortAlpha
  20. /// \~English
  21. /// \brief A function to sort the QStrings. Returns the order
  22. /// strings through the parameters (a is smallest, c is largest).
  23. /// \param a reference to first QSring
  24. /// \param b reference to second Qstring
  25. /// \param c reference to third QString
  26. /// \~Spanish
  27. /// \brief Función para ordenar QStrings. Devuelve los QStrings
  28. /// ordenados a través de los parámetros (a para el menor, c para el mayor).
  29. /// \param a referencia al primer QSring
  30. /// \param b referencia al segundo Qstring
  31. /// \param c referencia al tercer QString
  32. void mySortAlpha(QString &a, QString &b, QString &c);
  33. /// \fn mySortBeta
  34. /// \~English
  35. /// \brief A function to sort the QStrings. Returns the order
  36. /// strings through the parameters (a is smallest, c is largest).
  37. /// \param a reference to first QSring
  38. /// \param b reference to second Qstring
  39. /// \param c reference to third QString
  40. /// \~Spanish
  41. /// \brief Función para ordenar QStrings. Devuelve los QStrings
  42. /// ordenados a través de los parámetros (a para el menor, c para el mayor).
  43. /// \param a referencia al primer QSring
  44. /// \param b referencia al segundo Qstring
  45. /// \param c referencia al tercer QString
  46. void mySortBeta(QString &a, QString &b, QString &c);
  47. /// \fn mySortGamma
  48. /// \~English
  49. /// \brief A function to sort the QStrings. Returns the order
  50. /// strings through the parameters (a is smallest, c is largest).
  51. /// \param a reference to first QSring
  52. /// \param b reference to second Qstring
  53. /// \param c reference to third QString
  54. /// \~Spanish
  55. /// \brief Función para ordenar QStrings. Devuelve los QStrings
  56. /// ordenados a través de los parámetros (a para el menor, c para el mayor).
  57. /// \param a referencia al primer QSring
  58. /// \param b referencia al segundo Qstring
  59. /// \param c referencia al tercer QString
  60. void mySortGamma(QString &a, QString &b, QString &c);
  61. /// \fn mySortDelta
  62. /// \~English
  63. /// \brief First function to sort the QStrings. Returns the order
  64. /// strings through the parameters (a is smallest, c is largest).
  65. /// \param a reference to first QSring
  66. /// \param b reference to second Qstring
  67. /// \param c reference to third QString
  68. /// \~Spanish
  69. /// \brief Función para ordenar QStrings. Devuelve los QStrings
  70. /// ordenados a través de los parámetros (a para el menor, c para el mayor).
  71. /// \param a referencia al primer QSring
  72. /// \param b referencia al segundo Qstring
  73. /// \param c referencia al tercer QString
  74. void mySortDelta(QString &a, QString &b, QString &c);
  75. /// \fn validZuluTime
  76. /// \~English
  77. /// \brief Function to validate the arguments that will be passed to the
  78. /// Zulu functions. Returns the integer hour and minutes through last two parameters.
  79. /// \param time QString that contains the time in military format.
  80. /// \param zone QString that specifies military zone.
  81. /// \param hours hours, extracted from the time parameter
  82. /// \param minutes minutes, extracted from the time parameter
  83. /// \return true if the time and zone are valid.
  84. /// \~Spanish
  85. /// \brief Función para validar los argumentos que serán pasados a
  86. /// funciones Zulu. Devuelve (como enteros) la hora y minutos a través de los
  87. /// últimos dos parámetros.
  88. /// \param time QString que contiene la hora en formato militar, e.g. "15:22"
  89. /// \param zone QString que contiene zona militar.
  90. /// \param hours horas, extraida del argumento pasado a time.
  91. /// \param minutes minutos, extraidos del argumento pasado a time.
  92. /// \return true si la hora (time) y la zona son válidas.
  93. bool validZuluTime(const QString &time, const QString &zone, int &hours, int &minutes);
  94. /// \fn zuluAlpha
  95. /// \~English
  96. /// \brief Given the hour, minutes and military zone returns the Zulu time (as a QString)
  97. /// \param hours
  98. /// \param minutes
  99. /// \param zone
  100. /// \return a QString of the Zulu time, in military time format
  101. /// \~Spanish
  102. /// \brief Dado la hora, minutos y zona militar devuelve el tiempo Zulu (como QString)
  103. /// \param hours
  104. /// \param minutes
  105. /// \param zone
  106. /// \return un QString del tiempo Zulu, en formato de hora militar.
  107. QString zuluAlpha(int hours, int minutes, char zone);
  108. /// \fn zuluBeta
  109. /// \~English
  110. /// \brief Given the hour, minutes and military zone returns the Zulu time (as a QString)
  111. /// \param hours
  112. /// \param minutes
  113. /// \param zone
  114. /// \return a QString of the Zulu time, in military time format
  115. /// \~Spanish
  116. /// \brief Dado la hora, minutos y zona militar devuelve el tiempo Zulu (como QString)
  117. /// \param hours
  118. /// \param minutes
  119. /// \param zone
  120. /// \return un QString del tiempo Zulu, en formato de hora militar.
  121. QString zuluBeta(int hours, int minutes, char zone);
  122. /// \fn zuluGamma
  123. /// \~English
  124. /// \brief Given the hour, minutes and military zone returns the Zulu time (as a QString)
  125. /// \param hours
  126. /// \param minutes
  127. /// \param zone
  128. /// \return a QString of the Zulu time, in military time format
  129. /// \~Spanish
  130. /// \brief Dado la hora, minutos y zona militar devuelve el tiempo Zulu (como QString)
  131. /// \param hours
  132. /// \param minutes
  133. /// \param zone
  134. /// \return un QString del tiempo Zulu, en formato de hora militar.
  135. QString zuluGamma(int hours, int minutes, char zone);
  136. /// \fn zuluDelta
  137. /// \~English
  138. /// \brief Given the hour, minutes and military zone returns the Zulu time (as a QString)
  139. /// \param hours
  140. /// \param minutes
  141. /// \param zone
  142. /// \return a QString of the Zulu time, in military time format
  143. /// \~Spanish
  144. /// \brief Dado la hora, minutos y zona militar devuelve el tiempo Zulu (como QString)
  145. /// \param hours
  146. /// \param minutes
  147. /// \param zone
  148. /// \return un QString del tiempo Zulu, en formato de hora militar.
  149. QString zuluDelta(int hours, int minutes, char zone);
  150. // Constants for the rock, paper, scisor functions.
  151. const int TIE = 0;
  152. const int P1_WON = 1;
  153. const int P2_WON = 2;
  154. /// \fn RPSAlpha
  155. /// \~English
  156. /// \brief Given play by the first and second players, returns who won the rock, paper
  157. /// scisors match.
  158. /// \param p1 play by the first player, as represented by char 'R', 'P' or 'S'
  159. /// \param p2 play by the first player, as represented by char 'R', 'P' or 'S'
  160. /// \return a 0 if there was a tie, 1 if the first player won, 2 if the second player won.
  161. /// \~Spanish
  162. /// \brief Dado la jugada del jugador 1 y 2, devuelve quien ganó el juego de piedra,
  163. /// papel y tijera ((R)ock, (P)aper, (S)cisors)
  164. /// \param p1 jugada del primer jugador, representada por un caracter ('R','P','S')
  165. /// \param p1 jugada del segundo jugador, representada por un caracter ('R','P','S')
  166. /// \return a 0 si hubo empate, 1 si ganó el primer jugador, 2 si ganó el segundo.
  167. int RPSAlpha(char p1, char p2);
  168. /// \fn RPSBeta
  169. /// \~English
  170. /// \brief Given play by the first and second players, returns who won the rock, paper
  171. /// scisors match.
  172. /// \param p1 play by the first player, as represented by char 'R', 'P' or 'S'
  173. /// \param p2 play by the first player, as represented by char 'R', 'P' or 'S'
  174. /// \return a 0 if there was a tie, 1 if the first player won, 2 if the second player won.
  175. /// \~Spanish
  176. /// \brief Dado la jugada del jugador 1 y 2, devuelve quien ganó el juego de piedra,
  177. /// papel y tijera ((R)ock, (P)aper, (S)cisors)
  178. /// \param p1 jugada del primer jugador, representada por un caracter ('R','P','S')
  179. /// \param p1 jugada del segundo jugador, representada por un caracter ('R','P','S')
  180. /// \return a 0 si hubo empate, 1 si ganó el primer jugador, 2 si ganó el segundo.
  181. int RPSBeta(char p1, char p2);
  182. /// \fn RPSGamma
  183. /// \~English
  184. /// \brief Given play by the first and second players, returns who won the rock, paper
  185. /// scisors match.
  186. /// \param p1 play by the first player, as represented by char 'R', 'P' or 'S'
  187. /// \param p2 play by the first player, as represented by char 'R', 'P' or 'S'
  188. /// \return a 0 if there was a tie, 1 if the first player won, 2 if the second player won.
  189. /// \~Spanish
  190. /// \brief Dado la jugada del jugador 1 y 2, devuelve quien ganó el juego de piedra,
  191. /// papel y tijera ((R)ock, (P)aper, (S)cisors)
  192. /// \param p1 jugada del primer jugador, representada por un caracter ('R','P','S')
  193. /// \param p1 jugada del segundo jugador, representada por un caracter ('R','P','S')
  194. /// \return a 0 si hubo empate, 1 si ganó el primer jugador, 2 si ganó el segundo.
  195. int RPSGamma(char p1, char p2);
  196. /// \fn RPSDelta
  197. /// \~English
  198. /// \brief Given play by the first and second players, returns who won the rock, paper
  199. /// scisors match.
  200. /// \param p1 play by the first player, as represented by char 'R', 'P' or 'S'
  201. /// \param p2 play by the first player, as represented by char 'R', 'P' or 'S'
  202. /// \return a 0 if there was a tie, 1 if the first player won, 2 if the second player won.
  203. /// \~Spanish
  204. /// \brief Dado la jugada del jugador 1 y 2, devuelve quien ganó el juego de piedra,
  205. /// papel y tijera ((R)ock, (P)aper, (S)cisors)
  206. /// \param p1 jugada del primer jugador, representada por un caracter ('R','P','S')
  207. /// \param p1 jugada del segundo jugador, representada por un caracter ('R','P','S')
  208. /// \param zone
  209. /// \return a 0 si hubo empate, 1 si ganó el primer jugador, 2 si ganó el segundo.
  210. int RPSDelta(char p1, char p2);
  211. /// \fn initCheckWMaps
  212. /// \~English
  213. /// \brief Initialize the values in the dictionary (M) that is used throughout
  214. /// the check functions.
  215. /// \~Spanish
  216. /// \brief Inicializa los valores del diccionario que se utiliza a través del
  217. /// las funciones 'check'
  218. void initCheckWMaps();
  219. /// \fn validateCheckQty
  220. /// \~English
  221. /// \brief Given a QString determines its numerical value and if the
  222. /// the value is in the range [0,999999999]
  223. /// \param st a QString with a numeric value, e.g. "4520"
  224. /// \param qty unsigned integer to return the numeric value, e.g. 4520
  225. /// \return true if the QString was converted to an integer and is in the valid range
  226. /// \~Spanish
  227. /// \brief Dado un string determina su valor numérico y si el valor está en el
  228. /// rango [0,999999999]
  229. /// \param st un QString con un valor numérico, e.g. "4520"
  230. /// \param qty entero sin signo para devolver el valor numérico, e.g. 4520
  231. /// \return true si el QString se pudo convertir a entero y está en el rango
  232. bool validateCheckQty(QString st, unsigned int &qty);
  233. /// \fn wordForNumber
  234. /// \~English
  235. /// \brief Given a number n in [0,999] returns the word equivalent
  236. /// \param n the unsigned integer, e.g. 34
  237. /// \return a QString containing the number in words, e.g. "thirty four"
  238. /// \~Spanish
  239. /// \brief Dado un número entero en el rango [0,999] devuelve su representación en palabras
  240. /// \param n el entero sin signo, e.g. 34
  241. /// \return un QString que contiene el valor en palabras, e.g. "thirty four"
  242. QString wordForNumber(unsigned int n);
  243. /// \fn checkWAlpha
  244. /// \~English
  245. /// \brief Given a unsigned integer returns its value as a string of words (in English)
  246. /// \param n the unsigned integer, e.g. 42
  247. /// \return QString containing the value (in words), e.g. "fourty two"
  248. /// \~Spanish
  249. /// \brief Dado un entero sin signo devuelve su valor como un string de palabras (in English)
  250. /// \param n el entero sin signo, e.g. 42
  251. /// \return QString que contien el valor en palabras, e.g. "fourty two"
  252. QString checkWAlpha(unsigned int n);
  253. /// \fn checkWBeta
  254. /// \~English
  255. /// \brief Given a unsigned integer returns its value as a string of words (in English)
  256. /// \param n the unsigned integer, e.g. 42
  257. /// \return QString containing the value (in words), e.g. "fourty two"
  258. /// \~Spanish
  259. /// \brief Dado un entero sin signo devuelve su valor como un string de palabras (in English)
  260. /// \param n el entero sin signo, e.g. 42
  261. /// \return QString que contien el valor en palabras, e.g. "fourty two"
  262. QString checkWBeta(unsigned int n);
  263. /// \fn checkWGamma
  264. /// \~English
  265. /// \brief Given a unsigned integer returns its value as a string of words (in English)
  266. /// \param n the unsigned integer, e.g. 42
  267. /// \return QString containing the value (in words), e.g. "fourty two"
  268. /// \~Spanish
  269. /// \brief Dado un entero sin signo devuelve su valor como un string de palabras (in English)
  270. /// \param n el entero sin signo, e.g. 42
  271. /// \return QString que contien el valor en palabras, e.g. "fourty two"
  272. QString checkWGamma(unsigned int n);
  273. /// \fn checkWDelta
  274. /// \~English
  275. /// \brief Given a unsigned integer returns its value as a string of words (in English)
  276. /// \param n the unsigned integer, e.g. 42
  277. /// \return QString containing the value (in words), e.g. "fourty two"
  278. /// \~Spanish
  279. /// \brief Dado un entero sin signo devuelve su valor como un string de palabras (in English)
  280. /// \param n el entero sin signo, e.g. 42
  281. /// \return QString que contien el valor en palabras, e.g. "fourty two"
  282. QString checkWDelta(unsigned int n);
  283. #endif // FUNCTIONS_H