Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //#include "riesenie8.h"
- #if !defined( _RIESENIE_H_ )
- #define _RIESENIE_H_
- //1.uloha
- bool spravneCislo(const char *cislo);
- int cisloZRetazca(const char *cislo);
- //2.uloha
- int vratCislo(int index, const char **zoznamCisel, int pocet);
- //3.uloha
- class PoleCisel {
- int pocetCisel;
- int *pole;
- public:
- PoleCisel();
- void vlozPole(const char **zoznamCisel, int pocet);
- int cislo(int index);
- int velkost() { return pocetCisel; };
- //4.uloha
- PoleCisel(const PoleCisel &vstup);
- PoleCisel(PoleCisel &&vstup);
- PoleCisel &operator=(const PoleCisel &vstup);
- //5.uloha
- bool operator==(const PoleCisel &vstup);
- void operator+=(const PoleCisel &vstup);
- };
- #endif
- const bool DUMMY_BOOL = false;
- const int DUMMY_INT = -1;
- const int ZLE_CISLO = -99999;
- //1.uloha
- bool spravneCislo(const char *cislo) {
- if (cislo == nullptr || cislo == "" || strlen(cislo) == 0 || cislo == "-")
- return false;
- //printf("\n\n CISLO : %s\n\n", cislo);
- for (int i = 0; i < strlen(cislo); i++) {
- if ((cislo[i] >= '0' && cislo[i] <= '9') || cislo[i] == '-') {
- if (cislo[i] == '-' && i != 0)
- return false;
- continue;
- }
- else{
- return false;
- }
- }
- return true;
- }
- int cisloZRetazca(const char *cislo) {
- if (!(spravneCislo(cislo))) {
- return -99999;
- }
- else {
- return atoi(cislo);
- }
- }
- //2.uloha
- int vratCislo(int index, const char **zoznamCisel, int pocet) {
- if (index < 0 || index >= pocet) {
- return -99999;
- }
- else {
- return cisloZRetazca(zoznamCisel[index]);
- }
- }
- //3.uloha
- PoleCisel::PoleCisel() {
- pole = nullptr;
- pocetCisel = 0;
- }
- void PoleCisel::vlozPole(const char **zoznamCisel, int pocet) {
- if (pocet < 1) {
- pocetCisel = 0;
- pole = nullptr;
- }
- else {
- if (pole != nullptr) {
- delete pole;
- }
- pole = new int[pocet];
- int count = 0;
- int tmp = 0;
- for (int i = 0; i < pocet; i++) {
- tmp = vratCislo(i, zoznamCisel, pocet);
- if (tmp != -99999) {
- pole[count] = tmp;
- count++;
- }
- }
- pocetCisel = count;
- }
- }
- int PoleCisel::cislo(int index) {
- if (index < 0 || index > pocetCisel - 1)
- return -99999;
- return pole[index];
- }
- //4.uloha
- PoleCisel::PoleCisel(const PoleCisel &vstup) {
- pocetCisel = vstup.pocetCisel;
- if (pole != nullptr) {
- delete pole;
- }
- pole = new int[vstup.pocetCisel];
- for (int i = 0; i < vstup.pocetCisel; i++) {
- pole[i] = vstup.pole[i];
- }
- }
- PoleCisel::PoleCisel(PoleCisel &&vstup) {
- pocetCisel = vstup.pocetCisel;
- if (pole != nullptr) {
- delete pole;
- }
- pole = new int[vstup.pocetCisel];
- for (int i = 0; i < vstup.pocetCisel; i++) {
- pole[i] = vstup.pole[i];
- }
- vstup.pole = nullptr;
- vstup.pocetCisel = 0;
- }
- PoleCisel &PoleCisel::operator=(const PoleCisel &vstup) {
- if (&vstup != this){
- PoleCisel tmp(vstup);
- return tmp;
- }
- return *this;
- }
- //5.uloha
- bool PoleCisel::operator==(const PoleCisel &vstup) {
- if (vstup.pocetCisel != pocetCisel)
- return false;
- for (int i = 0; i < pocetCisel; i++) {
- if (pole[i] != vstup.pole[i])
- return false;
- }
- return true;
- }
- void PoleCisel::operator+=(const PoleCisel &vstup) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement