Menu

Program Must C Syntax Write Definition Generic Class Called Rectangle Data Members Length Q43781725

  1. The program must be in C# syntax.
  2. Write the definition for a generic class calledRectangle 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 ofthe rectangle
    area to calculate and return the area of therectangle
    show to return a text to display the length andwidth of the rectangle
    sameArea that has one parameter of type Rectangle.sameArea returns 1 if the two Rectangles have the same area, andreturns 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 Rectangleto find the new values of the length and the width

Subtract second area from first area and then find the ratio ofthe first Rectangle to find the new values of the length and thewidth

*

Multiply first area by second area and then find the ratio ofthe first Rectangle to find the new values of the length and thewidth

/

Divide first area by second area and then find the ratio of thefirst Rectangle to find the new values of the length and thewidth

<

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 firstRectangle

-=

Same as – operator and assign the result to the firstRectangle

*=

Same as * operator and assign the result to the firstRectangle

/=

Same as / operator and assign the result to the firstRectangle

  1. Write the definitions for each of the above memberfunctions.
  2. Write main function to create two rectangle pointers. Set thelength and width of the first rectangle to 5 and 2. Set the lengthand width of the second rectangle to 5 and 18.9. Display eachrectangle and its area and perimeter.

Check whether the two Rectangles have the same area and print amessage indicating the result. Set the length and width of thefirst rectangle to 15 and 6.3. Display each Rectangle and its areaand perimeter again. Again, check whether the two Rectangles havethe same area and print a message indicating the result

Expert Answer


Answer to The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members lengt…

OR