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!

Oldest comments (0)

Hey 😍

Want to help the DEV Community feel more like a community?

Head over to the Welcome Thread and greet some new community members!

It only takes a minute of your time, and goes a long way!