Thursday 15 July 2010

oop - Finding Perimeter and area of a Rectangle object? (C#) -


I know that the formula to find the area of ​​a rectangle is only the length * width, and peremiter formula 2 (length) + 2 (width) My question is, what is the most effective way of finding the area and perimeter of rectangular object made from other objects?

My code snippet:

  square rectangle {left public line {get; Set; } Public Line Top {Received; Set; } Receive the public line correct; Set; } Public line {received; Set; } Public Rectangle (): This (new line (new point), new point ())} {} public rectangle (line diagonal) {point start_aagonialpoint = diagnose; start; Point endangionpointpoint = diagnostic End Point; Int begXC = beginner GnialPoint XCoord; Int begYC = ExternalDioialPoint ICoord; Int endXC = Finished DeGonel Point.xCoord; Int endYC = Finished DeGonel Point. ICoord; Point Right Sideend = New Point (AndXC, BEGC); Point leftand = new point (BGXC, ANDYC); Right = New Line (Finished Degonial Point, Right Sideend); Left = new line (start application, leftendend); Top = new line (left sideend, end to denotiable point); Down = new line (right sideend, beginning application dagoni); }}  

I want to write two methods, to calculate the area, to calculate another perimeter, how should I go with the objects?

I know that I can take xfinal - yinitial for xinitial coordination and length for xfonal coordinate - width, but there is another / or better way of doing this with objects?

Thank you!

Your circumference is (ANDXC - BQXC) * 2 + (ANDYC ) - begYC) * 2

Your area is (AndXC - BQXC) * (ANDYC - BIICC)

... Poitic X and Y instructions to hold the digits (otherwise < / P>

If the area and perimeter are likely to be called, you can calculate them and store them on the int


No comments:

Post a Comment