Answer to Question #185880 in C++ for Laiba

Question #185880

Let’s assume we have a class ‘Arithmetic’ with two member functions Add() and Subtract(). Suppose Add() function is defined within class then how will the subtract() function be defined out of the class boundary. Explain it with the help of some suitable program.


1
Expert's answer
2021-04-26T15:45:54-0400
#include <iostream>
using namespace std;
class Arithmetic{
    int x, y;
    public:
    Arithmetic(int a, int b){
        x = a; y = b;
    }
    int Add(){return x + y;}
    int Subtract();
};
int Arithmetic::Subtract(){
    return x - y;
}
int main(){
    int x, y;
    cout<<"Enter first integer: ";
    cin>>x;
    cout<<"Enter second integer: ";
    cin>>y;
    Arithmetic arithmetic(x, y);
    cout<<x<<" + "<<y<<" = "<<arithmetic.Add()<<endl;
    cout<<x<<" - "<<y<<" = "<<arithmetic.Subtract()<<endl;
    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