Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. //#include "riesenie8.h"
  6.  
  7. #if !defined( _RIESENIE_H_ )
  8. #define _RIESENIE_H_
  9.  
  10. //1.uloha
  11. bool spravneCislo(const char *cislo);
  12. int cisloZRetazca(const char *cislo);
  13.  
  14. //2.uloha
  15. int vratCislo(int index, const char **zoznamCisel, int pocet);
  16.  
  17. //3.uloha
  18. class PoleCisel {
  19.   int pocetCisel;
  20.   int *pole;
  21.  public:
  22.   PoleCisel();
  23.   void vlozPole(const char **zoznamCisel, int pocet);
  24.   int cislo(int index);
  25.   int velkost() { return pocetCisel; };
  26.  
  27. //4.uloha
  28.   PoleCisel(const PoleCisel &vstup);
  29.   PoleCisel(PoleCisel &&vstup);
  30.   PoleCisel &operator=(const PoleCisel &vstup);
  31.  
  32. //5.uloha
  33.   bool operator==(const PoleCisel &vstup);
  34.   void operator+=(const PoleCisel &vstup);
  35. };
  36. #endif
  37.  
  38. const bool DUMMY_BOOL = false;
  39. const int DUMMY_INT = -1;
  40. const int ZLE_CISLO = -99999;
  41.  
  42. //1.uloha
  43. bool spravneCislo(const char *cislo) {
  44.     if (cislo == nullptr || cislo == "" || strlen(cislo) == 0 || cislo == "-")
  45.         return false;
  46.  
  47.     //printf("\n\n CISLO : %s\n\n", cislo);
  48.  
  49.     for (int i = 0; i < strlen(cislo); i++) {
  50.         if ((cislo[i] >= '0' &&  cislo[i] <= '9') || cislo[i] == '-') {
  51.             if (cislo[i] == '-' && i != 0)
  52.                 return false;
  53.             continue;
  54.         }
  55.         else{
  56.             return false;
  57.         }
  58.     }
  59.   return true;
  60. }
  61.  
  62. int cisloZRetazca(const char *cislo) {
  63.     if (!(spravneCislo(cislo))) {
  64.         return -99999;
  65.     }
  66.     else {
  67.         return atoi(cislo);
  68.     }
  69. }
  70.  
  71. //2.uloha
  72. int vratCislo(int index, const char **zoznamCisel, int pocet) {
  73.     if (index < 0 || index >= pocet) {
  74.         return -99999;
  75.     }
  76.     else {
  77.         return cisloZRetazca(zoznamCisel[index]);
  78.     }
  79. }
  80.  
  81. //3.uloha
  82. PoleCisel::PoleCisel() {
  83.     pole = nullptr;
  84.     pocetCisel = 0;
  85. }
  86.  
  87. void PoleCisel::vlozPole(const char **zoznamCisel, int pocet) {
  88.     if (pocet < 1) {
  89.         pocetCisel = 0;
  90.         pole = nullptr;
  91.     }
  92.     else {
  93.         if (pole != nullptr) {
  94.             delete pole;
  95.         }
  96.         pole = new int[pocet];
  97.         int count = 0;
  98.         int tmp = 0;
  99.         for (int i = 0; i < pocet; i++) {
  100.             tmp = vratCislo(i, zoznamCisel, pocet);
  101.             if (tmp != -99999) {
  102.                 pole[count] = tmp;
  103.                 count++;
  104.             }
  105.         }
  106.         pocetCisel = count;
  107.     }
  108.  
  109. }
  110.  
  111. int PoleCisel::cislo(int index) {
  112.     if (index < 0 || index > pocetCisel - 1)
  113.         return -99999;
  114.     return pole[index];
  115. }
  116.  
  117.  
  118. //4.uloha
  119. PoleCisel::PoleCisel(const PoleCisel &vstup) {
  120.     pocetCisel = vstup.pocetCisel;
  121.     if (pole != nullptr) {
  122.         delete pole;
  123.     }
  124.     pole = new int[vstup.pocetCisel];
  125.     for (int i = 0; i < vstup.pocetCisel; i++) {
  126.         pole[i] = vstup.pole[i];
  127.     }
  128. }
  129.  
  130. PoleCisel::PoleCisel(PoleCisel &&vstup) {
  131.     pocetCisel = vstup.pocetCisel;
  132.     if (pole != nullptr) {
  133.         delete pole;
  134.     }
  135.     pole = new int[vstup.pocetCisel];
  136.     for (int i = 0; i < vstup.pocetCisel; i++) {
  137.         pole[i] = vstup.pole[i];
  138.     }
  139.     vstup.pole = nullptr;
  140.     vstup.pocetCisel = 0;
  141.    
  142.    
  143. }
  144.  
  145. PoleCisel &PoleCisel::operator=(const PoleCisel &vstup) {
  146.     if (&vstup != this){
  147.         PoleCisel tmp(vstup);
  148.         return tmp;
  149.     }
  150.  
  151.     return *this;
  152.    
  153. }
  154.  
  155. //5.uloha
  156. bool PoleCisel::operator==(const PoleCisel &vstup) {
  157.     if (vstup.pocetCisel != pocetCisel)
  158.         return false;
  159.    
  160.     for (int i = 0; i < pocetCisel; i++) {
  161.         if (pole[i] != vstup.pole[i])
  162.             return false;
  163.     }
  164.  
  165.     return true;
  166. }
  167.  
  168. void PoleCisel::operator+=(const PoleCisel &vstup) {
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement