Question: Question: Write a C + + program that creates a class Rectangle with two private data members length and width. The class should have: A

Question:
Write a C++ program that creates a class Rectangle with two private data members length and width. The class should have:
A constructor to initialize the length and width.
A member function area() that returns the area of the rectangle.
A member function perimeter() that returns the perimeter of the rectangle.
A function compareArea(Rectangle &other) that compares the area of the current rectangle with another rectangle and returns:
1 if the current rectangle's area is larger,
-1 if the current rectangle's area is smaller,
0 if both areas are equal.
Write a main function to demonstrate the use of this class by creating two Rectangle objects, comparing their areas, and displaying the result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!