Ask Question
2 November, 06:03

ppose we have a Rectangle class that includes length and width attributes, of type int, both set by the constructor. Define an equals method for this class so that two rectangle objects are considered equal ifThey have the exact same length and width. They have the same dimensions-that is, they are congruent. They have the same shape-that is, they are similar. They have the same perimeter. They have the same area.

+5
Answers (1)
  1. 2 November, 09:38
    0
    Check the explanation

    Explanation:

    #include

    using namespace std;

    class Rectangle{

    public:

    int length;

    int breadth;

    Rectangle (int l, int b) {

    length = l;

    breadth = b;

    }

    int area () {

    return length*breadth;

    }

    int perimeter () {

    return 2 * (length+breadth);

    }

    bool equals (Rectangle * r) {

    / / They have the exact same length and width.

    if (r->length = = length && r->breadth = = breadth)

    return true;

    / / They have the same area

    if (r->area () = = area ())

    return true;

    / / They have the same perimeter

    if (r->perimeter () = = perimeter ())

    return true;

    / / They have the same shape-that is, they are similar.

    if (r->length/length = = r->breadth/breadth)

    return true;

    return false;

    }

    };

    int main () {

    Rectangle * r_1 = new Rectangle (6,3);

    Rectangle * r_2 = new Rectangle (3,6);

    cout
    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “ppose we have a Rectangle class that includes length and width attributes, of type int, both set by the constructor. Define an equals ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers