Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.uloha
- bool je_cislica(char vstup) {
- return isdigit(vstup);
- }
- bool spravneCislo(const char *cislo) {
- if ((cislo == NULL) || (cislo == nullptr) || (cislo == "")) {
- return false;
- }
- if (*cislo == '-') {
- cislo++;
- if (*cislo == '\0') {
- return false;
- }
- }
- while (*cislo != '\0') {
- if (!je_cislica(*cislo)){
- return false;
- }
- cislo++;
- }
- return true;
- }
- int cisloZRetazca(const char *cislo) {
- if (spravneCislo(cislo)) {
- return atoi(cislo);
- }
- return ZLE_CISLO;
- }
- //2.uloha
- int vratCislo(int index, const char **zoznamCisel, int pocet) {
- if (index < 0 || index >= pocet) {
- return ZLE_CISLO;
- }
- if (spravneCislo(zoznamCisel[index])) {
- return cisloZRetazca(zoznamCisel[index]);
- }
- return ZLE_CISLO;
- }
- //3.uloha
- PoleCisel::PoleCisel() {
- pocetCisel = 0;
- pole = nullptr;
- }
- void PoleCisel::vlozPole(const char **zoznamCisel, int pocet) {
- if (pocet < 1) {
- pocetCisel = 0;
- pole = nullptr;
- }
- int pocet_vlozenych = 0;
- delete[] pole;
- pole = new int[pocet];
- int pozicia = 0;
- for (int i = 0; i < pocet; i++){
- if (spravneCislo(zoznamCisel[i])) {
- pole[pozicia] = cisloZRetazca(zoznamCisel[i]);
- pozicia++;
- pocet_vlozenych++;
- }
- }
- pocetCisel = pocet_vlozenych;
- }
- int PoleCisel::cislo(int index) {
- if (pocetCisel <= index) {
- return ZLE_CISLO;
- }
- return pole[index];
- }
- //4.uloha
- PoleCisel::PoleCisel(const PoleCisel &vstup) {
- pole = vstup.pole;
- pocetCisel = vstup.pocetCisel;
- }
- PoleCisel::PoleCisel(PoleCisel &&vstup) {
- pole = vstup.pole;
- pocetCisel = vstup.pocetCisel;
- vstup.pole = 0;
- vstup.pocetCisel = 0;
- }
- PoleCisel &PoleCisel::operator=(const PoleCisel &vstup) {
- pole = vstup.pole;
- pocetCisel = vstup.pocetCisel;
- return *this;
- }
- //5.uloha
- bool PoleCisel::operator==(const PoleCisel &vstup) {
- if (pocetCisel != vstup.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) {
- int *pom = new int[pocetCisel + vstup.pocetCisel];
- int pocitadlo = 0;
- for (int i = 0; i < pocetCisel; i++) {
- pom[i] = pole[i];
- //pom++;
- pocitadlo++;
- }
- for (int i = 0; i < vstup.pocetCisel; i++) {
- pom[pocitadlo] = vstup.pole[i];
- pocitadlo++;
- //pom++;
- }
- delete[] pole;
- pole = pom;
- pocetCisel = pocetCisel + vstup.pocetCisel;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement