Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. //1.uloha
  2.  
  3. bool je_cislica(char vstup) {
  4. return isdigit(vstup);
  5. }
  6.  
  7. bool spravneCislo(const char *cislo) {
  8.  
  9. if ((cislo == NULL) || (cislo == nullptr) || (cislo == "")) {
  10. return false;
  11. }
  12.  
  13. if (*cislo == '-') {
  14. cislo++;
  15. if (*cislo == '\0') {
  16. return false;
  17. }
  18. }
  19.  
  20.  
  21. while (*cislo != '\0') {
  22. if (!je_cislica(*cislo)){
  23. return false;
  24. }
  25. cislo++;
  26. }
  27. return true;
  28. }
  29.  
  30. int cisloZRetazca(const char *cislo) {
  31. if (spravneCislo(cislo)) {
  32. return atoi(cislo);
  33. }
  34. return ZLE_CISLO;
  35. }
  36.  
  37. //2.uloha
  38. int vratCislo(int index, const char **zoznamCisel, int pocet) {
  39. if (index < 0 || index >= pocet) {
  40. return ZLE_CISLO;
  41. }
  42. if (spravneCislo(zoznamCisel[index])) {
  43. return cisloZRetazca(zoznamCisel[index]);
  44. }
  45. return ZLE_CISLO;
  46. }
  47.  
  48. //3.uloha
  49. PoleCisel::PoleCisel() {
  50. pocetCisel = 0;
  51. pole = nullptr;
  52. }
  53.  
  54. void PoleCisel::vlozPole(const char **zoznamCisel, int pocet) {
  55. if (pocet < 1) {
  56. pocetCisel = 0;
  57. pole = nullptr;
  58. }
  59. int pocet_vlozenych = 0;
  60. delete[] pole;
  61. pole = new int[pocet];
  62. int pozicia = 0;
  63. for (int i = 0; i < pocet; i++){
  64. if (spravneCislo(zoznamCisel[i])) {
  65. pole[pozicia] = cisloZRetazca(zoznamCisel[i]);
  66. pozicia++;
  67. pocet_vlozenych++;
  68. }
  69. }
  70. pocetCisel = pocet_vlozenych;
  71. }
  72.  
  73. int PoleCisel::cislo(int index) {
  74. if (pocetCisel <= index) {
  75. return ZLE_CISLO;
  76. }
  77. return pole[index];
  78. }
  79.  
  80. //4.uloha
  81. PoleCisel::PoleCisel(const PoleCisel &vstup) {
  82. pole = vstup.pole;
  83. pocetCisel = vstup.pocetCisel;
  84. }
  85.  
  86. PoleCisel::PoleCisel(PoleCisel &&vstup) {
  87. pole = vstup.pole;
  88. pocetCisel = vstup.pocetCisel;
  89. vstup.pole = 0;
  90. vstup.pocetCisel = 0;
  91. }
  92.  
  93. PoleCisel &PoleCisel::operator=(const PoleCisel &vstup) {
  94. pole = vstup.pole;
  95. pocetCisel = vstup.pocetCisel;
  96. return *this;
  97. }
  98.  
  99. //5.uloha
  100. bool PoleCisel::operator==(const PoleCisel &vstup) {
  101. if (pocetCisel != vstup.pocetCisel) {
  102. return false;
  103. }
  104.  
  105. for (int i = 0; i < pocetCisel; i++) {
  106. if (pole[i] != vstup.pole[i]) {
  107. return false;
  108. }
  109. }
  110. return true;
  111. }
  112.  
  113. void PoleCisel::operator+=(const PoleCisel &vstup) {
  114. int *pom = new int[pocetCisel + vstup.pocetCisel];
  115. int pocitadlo = 0;
  116. for (int i = 0; i < pocetCisel; i++) {
  117. pom[i] = pole[i];
  118. //pom++;
  119. pocitadlo++;
  120. }
  121. for (int i = 0; i < vstup.pocetCisel; i++) {
  122. pom[pocitadlo] = vstup.pole[i];
  123. pocitadlo++;
  124. //pom++;
  125. }
  126. delete[] pole;
  127. pole = pom;
  128. pocetCisel = pocetCisel + vstup.pocetCisel;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement