Answer to Question #180914 in C++ for Shashank Singh

Question #180914
Write a program to overload binary – (minus) operator for Number class using friend function. Number class have
two data members as num1 and num2.
1
Expert's answer
2021-04-13T07:23:23-0400
using namespace std;
#include <iostream>

class OverLoading
{
    private:
    int value;

    public:
    OverLoading()
    { value = 0;}

    OverLoading(int c)
    { value = c;}

    friend OverLoading operator-(OverLoading &S1, OverLoading &S2);

    void printValue()
    {
        cout<<"Value is : "<<value<<endl;
    }
};

OverLoading operator-(OverLoading &S1, OverLoading &S2)
{
    OverLoading S;
    S = S1.value-S2.value;
    return S;
}

int main()
{
    int i = 0;
    OverLoading S1(600);
    OverLoading S2(200);
    OverLoading S3;

    S3 = S1 - S2;

    cout<<"S1 :"<<endl;
    S1.printValue();

    cout<<"S2 :"<<endl;
    S2.printValue();

    cout<<"S3 :"<<endl;
    S3.printValue();

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS