Opearot Overloading

type operator sign (parameters) { /*... body ...*/ }
#include<iostream>

using namespace std;

class Complex
{
public:
    int a,b;
    void input(string s)
    {
        int v1=0;
        int i=0;
        while(s[i]!='+')
        {
            v1=v1*10+s[i]-'0';
            i++;
        }
        while(s[i]==' ' || s[i]=='+'||s[i]=='i')
        {
            i++;
        }
        int v2=0;
        while(i<s.length())
        {
            v2=v2*10+s[i]-'0';
            i++;
        }
        a=v1;
        b=v2;
    }
};

ostream& operator<<(ostream& os, const Complex& c) {
    return os << c.a << (c.b > 0 ? '+' : '-') << 'i' << c.b;
}

Complex operator+(const Complex& a, const Complex& b) { 
    return { a.a + b.a, a.b + b.b };
}

int main()
{
    Complex x,y;
    string s1,s2;
    cin>>s1;
    cin>>s2;
    x.input(s1);
    y.input(s2);
    Complex z=x+y;
    cout<<z<<endl;
}

Class Interfaces

class Person {
    private:
        string name;
        int age;
    protected:
        int cur_id;
    public:
        virtual void getdata(){
            cin >> name;
            cin >> age;
        }
        virtual void putdata(){
            cout << name << " " << age;
        }
};

class Professor : public Person {
    private:
        int npubs;
        static size_t count;
    public:
        Professor() {cur_id = ++count;}
        void getdata() override {
            Person::getdata();
            cin >> npubs;
        }

        void putdata() override {
            Person::putdata();
            cout << " " << npubs << " " << cur_id << endl;
        }
};

class Student : public Person {
    private:
        int marks[6];
        static size_t count;
    public:
        Student() {cur_id = ++count;}

        void getdata() override {
            Person::getdata();
            for(int i=0; i<6; ++i) {
                cin >> marks[i];
            }
        }

        void putdata() override {
            int s = 0;
            for(int i=0; i<6; ++i) 
                s += marks[i];
            Person::putdata();
            cout << " " << s << " " << cur_id << endl;
        }
};

size_t Professor::count = 0;
size_t Student::count = 0;

Operator Overloading

class MyClass {
    private:
        //...

    public:
        //...

        friend bool operator < (const MyClass& a, const MyClass& b){
            return (...);
        }

        friend ostream& operator<<(ostream& out, const MyClass& a){
            out << ... ;
            return out;
        }
};

In [ ]: