DEV Community 👩‍💻👨‍💻

Quoc Bao
Quoc Bao

Posted on • Updated on

Introduction to OOP and array class implementation [part 1]

Object-oriented programming (OOP) is an important knowledge taught in schools and programming classes. It is a concept that relies on the creation of classes and objects which helps coding more efficient with reusable code blocks of well-defined functions. Today, I will show you how to implement a simple 1D array class. Throughout the post, important OOP terminologies and concepts will be discussed for the sake of better understanding.

class Array
    int *A;
    int na = 0;
    int capacity_a = 1;

    void deepcopy(const Array &a);


    void insert(int);
    void print();

    Array(const Array &other);
    Array &operator=(const Array &other);
    Array operator+(Array other);

    int view_na();
    void set_na(int);
    int getElement(int index);
    void setElement(int index, int value);

    void quicksort(int left, int right);

    friend istream &operator>>(istream &in, Array &a);
    friend ostream &operator<<(ostream &out, Array a);
Enter fullscreen mode Exit fullscreen mode

Read more here!

Latest comments (0)

All DEV content is created by the community!

Hey, if you're landing here for the first time, you should know that this website is a global community of folks who blog about their experiences to help folks like you out.

Sign up now if you're curious. It's free!