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

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...