The Following code :
=========================
#include<iostream.h>
#include<conio.h>
#include<math.h>
class Rectangle{
private:
float l,w;
public:
Rectangle(float L=0,float W=0):l(L),w(W){}
void Output(){cout<<"L="<<l<<"\tW="<<w<<"\tArea="<<area()<<endl;}
Rectangle operator=(float s);
Rectangle operator+(Rectangle p);
float operator -(Rectangle p);
int operator >(Rectangle p);
int operator ==(Rectangle p);
float operator *();
float operator!();
float area(){return l*w;}
};
Rectangle Rectangle::operator=(float s){
//float w1,l1;
w=sqrt(s/2);
l=2*w;
return Rectangle(l,w);
}
Rectangle Rectangle::operator+(Rectangle p){
float w1,l1;
l1=l+p.l;
w1=w+p.w;
return Rectangle(l1,w1);
}
float Rectangle::operator-(Rectangle p){
return fabs(area()-p.area());
}
int Rectangle::operator>(Rectangle p){
return (area()>p.area());
}
int Rectangle::operator==(Rectangle p){
return (area()==p.area());
}
float Rectangle::operator*(){
return area();
}
float Rectangle::operator!(){
float d;
d=sqrt(l*l+w*w);
return d;
}
void main(){Rectangle p1(20,10),p2(10,5),p3(40,30);
cout<<"Output befor Overload:"<<endl;
p1.Output();
p2.Output();
p3.Output();
cout<<"after overload:"<<endl;
p1=10.0;p1.Output();
p3=p1+p2;p3.Output();
float s1,s2,s3;
s1=p1-p2;cout<<"S1="<<s1<<endl;
s2=*p1;cout<<"s2="<<s2<<endl;
s3=!p1;cout<<"Area of p1="<<s3<<endl;
if(p1>p2)cout<<"Area of p1>p2:"<<endl;
else if(p1==p2)cout<<"Area of p1=p2:"<<endl;
else cout<<"Area of p1<p2:"<<endl;
}
//Leave us a command here ..!
0 comments:
Post a Comment