Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
1.5 kB
2
Indexable
Never
#include <iostream>
using namespace std;

class Buffer{
private:
public:
    Buffer(){
        cout << "Konstruktor Buffer" << endl;
    }
    ~Buffer(){
        cout << "Destruktor Buffer" << endl;
    }
    virtual void add(int a) = 0;
    virtual void write() = 0;
};

class BufferArr: public Buffer{
private:
    int size;
    int *arr;
    int occ = sizeof(arr);
public:
    // KONSTURKOTRY I DESTRUKTORY
    BufferArr(){
        cout << "Konstruktor BufferArr" << endl;
        BufferArr *arr = new BufferArr[100];
    }
    BufferArr(int size){
        cout << "Konstruktor parametrowy BufferARR" << endl;
        BufferArr *arr = new BufferArr[size];
    }
    ~BufferArr(){
        cout << "Destruktor BufferArr" << endl;
        delete [] arr;
    }
    // GETTERY I SETTERY
    int get_arr(){
        return *arr;
    }
    void set_arr(int *s_arr){
        arr = s_arr;
    }
    int get_size(){
        return size;
    }
    void set_size(int s_size){
        size = s_size;
    }
    //  METODY
    void add(int a){
        if( size-occ >= 0 ){
            arr[occ] = a;
            occ++;
        }
        else if( size==occ ){
            cout << "Brak wolnych miejsc" << endl;
        }
    }
    void write(){
        for(int i=0; i<size; i++){
            cout << arr[i] << "\t" << endl;
        }
    }
};

class BufferFile: public Buffer{
private:
public:
};

int main(){
    BufferArr object1(20);
    // object1.add(5);

    return 0;
}