Sunday, February 25, 2018

C++ : Operator overloading example program

#include <iostream>
using namespace std;
class Box
{
private:
double length, breadth, height;
public:
Box(double a = 0, double b = 0, double c = 0) :
length(a), breadth(b), height(c) {};
double getDimension(){
return length + breadth + height;
}
Box operator+(const Box& x){ // Fill tme of the func
Box box;
 box.length= x.length + length;// Fill the statement
box.breadth= x.breadth + breadth; // Fill the statement
box.height= x.height + height;// Fill the statement
return box;
}
};
int main(){
double l = 0, b = 0, h = 0;
cin >> l; cin >> b; cin >> h;
Box Box1(5.00, 6.00, 7.00), Box2(l, b, h), Box3;
Box3 = Box1 + Box2;
double dim = Box3.getDimension();
cout << dim;
return 0;
}

Thanks
Happy Computing !

No comments:

Post a Comment

Sacred Thought

28 April 2024 Today I am going to explain verse 31 - 38 chapter two for you all. There is no opportunity better than a righteous war (सत्य औ...