Question: The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members length and width. The class
- The program must be in C# syntax.
- Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea returns 1 if the two Rectangles have the same area, and returns 0 if they don't.
Overload the following operators: -
| Operators | Description |
| - (unary) | Length and width will change sign |
| + | Add bother areas and then find the ratio of the first Rectangle to find the new values of the length and the width |
| - | Subtract second area from first area and then find the ratio of the first Rectangle to find the new values of the length and the width |
| * | Multiply first area by second area and then find the ratio of the first Rectangle to find the new values of the length and the width |
| / | Divide first area by second area and then find the ratio of the first Rectangle to find the new values of the length and the width |
| < | Compare the areas |
| > | Compare the areas |
| <= | Compare the areas |
| >= | Compare the areas |
| == | Compare the areas |
| != | Compare the areas |
| = | Assign the length and width to the first Rectangle |
| += | Same as + operator and assign the result to the first Rectangle |
| -= | Same as - operator and assign the result to the first Rectangle |
| *= | Same as * operator and assign the result to the first Rectangle |
| /= | Same as / operator and assign the result to the first Rectangle |
- Write the definitions for each of the above member functions.
- Write main function to create two rectangle pointers. Set the length and width of the first rectangle to 5 and 2. Set the length and width of the second rectangle to 5 and 18.9. Display each rectangle and its area and perimeter.
Check whether the two Rectangles have the same area and print a message indicating the result. Set the length and width of the first rectangle to 15 and 6.3. Display each Rectangle and its area and perimeter again. Again, check whether the two Rectangles have the same area and print a message indicating the result
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
