: Over load unary pre fix operator that first take a vale ,decrement it first then multiply it with other two number and display result that reflect the effect of decrement operator
Answers
Explanation:
Over load unary pre fix operator that first take a vale ,decrement it first then multiply it with other two number and display result that reflect the effect of decrement operator of following
#include<iostream>
using namespace std;
/*defining a class*/
class Triangle{
private:
double width;
double height;
public:
/*constructor*/
Triangle(){
}
/*Parameterized Constructor*/
Triangle(double x, double y){
width=x;
height=y;
}
/*calculating area of triangle*/
double cal_area(){
return (height*width)/2;
}
/*operator overloading -*/
Triangle operator - (Triangle &t) {
Triangle t1;
/*subtarcting a smaller value from greater value as area can not be negative*/
/*finding a difference between height */
if(height > t.height){
t1.height = height - t.height;
}
else{
t1.height = t.height - height;
}
/*finding a differencr between width*/
if( width > t.width){
t1.width = width - t.width;
}
else{
t1.width = t.width - width;
}
return t1;
}
};
int main(){
Triangle T1(15,15); /*creating 1 object with static value means fixed value*/
Triangle T2(20,20); /*creating 2nd object with static value means fixed value*/
Triangle T3=T2-T1; /*defining a third object and performing a subtraction between 1 and 2 */
//T3=T2-T1;
cout<<"The area of Triangle is: "<<T3.cal_area();