Answer to Question #248857 in C++ for rajeeb

Question #248857

Write a program to subtract two time objects and stored the result in 3rd object using operator member function and friend function


1
Expert's answer
2021-10-10T13:23:11-0400
#include <iostream>
using namespace std;
class objectB;


class objectA {
    
    public:
        
        objectA() : nA(12) {}
        
    private:
        int nA;
        
         
         friend int subtract(objectA, objectB);
};


class objectB {


    public:
       
        objectB() : nB(6) {}
    
    private:
        int nB;
 
        
        friend int subtract(objectA, objectB);
};
class objectC{
	friend int subtract(objectA, objectB);
};


int subtract(objectA objA, objectB objB) {
    return (objA.nA - objB.nB);
}


int main() {
    objectA objA;
    objectB objB;
    cout << "Result in 3rd object is: " << subtract(objA, objB);
    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