Answer to Question #269909 in C++ for bbb

Question #269909

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


1
Expert's answer
2021-11-22T07:08:49-0500


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS