DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Peter Bao
Peter 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
{
private:
    int *A;
    int na = 0;
    int capacity_a = 1;

    void deepcopy(const Array &a);

public:
    Array();
    Array(int);
    ~Array();

    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!

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.