#include <iostream>
using namespace std;
class Sum{
    private:
        int q;
        int r;
    public:
        Sum(){
            q=0;
            r=0;
        }
        void In(){
            cout<<"\nEnter the value of q: ";
            cin>>q;
            cout<<"\nEnter the value of r: ";
            cin>>r;
        }
        void Display(){
            cout<<"\nThe value of q is: "<<q;
            cout<<"\nThe value of r is: "<<r;
        }
        Sum operator + (const Sum& obj) {
        Sum temp;
        temp.q = q + obj.q;
        temp.r = r + obj.r;
        return temp;
    }
};
int main()
{
    Sum m,n,o;
    m.In();
    o.In();
    n=m+o;
    m.Display();
    n.Display();
    o.Display();
    return 0;
}
Output
Comments