daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "klasa.h"
  2. #include <stdio.h>
  3. #include <malloc.h>
  4.  
  5. DynArray::DynArray() {
  6.     this->size=0;
  7.     this->number=0;
  8.     this->tab=((int*) malloc ((size)* sizeof(int)));
  9. }
  10.  
  11. DynArray::DynArray(int size,int number) {
  12.     this->size=size;
  13.     this->number=number;
  14.     this->tab=((int*) malloc ((size)* sizeof(int)));
  15.     for(int i=0; i<this->size; i++) {
  16.         this->tab[i]=number;
  17.     }
  18. }
  19.  
  20. DynArray::DynArray(const DynArray&dyn) {
  21.     this->size=dyn.size;
  22.     this->number=dyn.number;
  23.     this->tab=((int*) malloc ((dyn.size)* sizeof(int)));
  24.     for(int i=0; i<dyn.size; i++) {
  25.         this->tab[i]=dyn.tab[i];
  26.     }
  27. }
  28.  
  29. DynArray::~DynArray(){
  30.     printf("D");
  31.     free (tab);
  32. }
  33.  
  34. int DynArray::Size() {
  35.     return this->size;
  36. }
  37. void DynArray::Display() {
  38.     if(this->size==0) {
  39.         printf("pusta tablica\n");
  40.     } else {
  41.         printf("[");
  42.         for(int i=0; i<(this->size)-1; i++) {
  43.             printf("%d, ", this->tab[i]);
  44.         }
  45.         printf("%d", this->tab[(this->size)-1]);
  46.         printf("]\n");
  47.     }
  48. }
  49.  
  50. DynArray & DynArray::operator+=(const int a) {
  51.     if (this->size==0) {
  52.         this->size=1;
  53.         tab=((int*) realloc (tab,1* sizeof(int)));
  54.         tab[0]=a;
  55.        
  56.     }
  57.  
  58.     else {
  59.         this->size++;
  60.         this->tab=((int*) realloc (tab,(this->size)* sizeof(int)));
  61.         this->tab[(this->size)-1]=a;
  62.  
  63.     }
  64.     return *this;
  65. }
  66.  
  67. DynArray & DynArray::operator!() {
  68.     if (this->size==0) {
  69.     }
  70.  
  71.     else {
  72.         for(int i=0; i<this->size; i++) {
  73.             this->tab[i]=(0-(this->tab[i]));
  74.         }
  75.     }
  76.     return *this;
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top