1.Create a datatype Rectangle, where a Rectangle is defined by Length & Width. Your Program should be capable to compute:
uArea (LxW)
uPerimeter 2(L+W)
ucompare two rectangles with respect to the area and return true if two rectangles are equal, False otherwise
#include <iostream>
using namespace std;
class Rectangle{
private:
int length;
int width;
public:
int uArea(){
return (length*width);
}
int uPerimeter(){
return 2*(length+width);
}
static bool uCompare(Rectangle r1,Rectangle r2){
cout<<"\nEnter length of the first rectangle: ";
cin>>r1.length;
cout<<"\nEnter width of the first rectangle: ";
cin>>r1.width;
cout<<"\nEnter length of the second rectangle: ";
cin>>r2.length;
cout<<"\nEnter width of the second rectangle: ";
cin>>r2.width;
if(r1.uArea()==r2.uArea()){
return true;
}
else{
return false;
}
}
};
int main()
{
Rectangle rec1,rec2;
bool comp=rec1.uCompare(rec1,rec2);
cout<<"\nArea of rectangle 1 = "<<rec1.uArea();
cout<<"\nPerimeter of rectangle 1 = "<<rec2.uArea();
cout<<"\nArea of rectangle 2 = "<<rec1.uArea();
cout<<"\nPerimeter of rectangle 2 = "<<rec2.uArea();
return 0;
}
Comments
Leave a comment