Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
someone please show me how to Create a class(es) to describe a Rectangle.
Also provide the following functionalities:
 Constructor that receive eight integers to initialise the four corner
points of a rectangle
 Constructor that receive 4 points to initialise the rectangle
Posted
Comments
Ankur\m/ 8-Sep-10 7:31am    
What have you tried?
Kubajzz 8-Sep-10 7:33am    
Reason for my vote of 1
Yet another homework? Show some effort first, then there will be many people willing to help you.
Per Söderlund 8-Sep-10 7:39am    
I agree. Do you want a System.Drawing.Rectangle
or just the points for a rectangle inside of a class?
Toli Cuturicu 8-Sep-10 11:53am    
Reason for my vote of 1
homework
Sandeep Mewara 8-Sep-10 13:15pm    
Reason for my vote of 1
No effort

1 solution

I think you are going to have to think about this: If you have eight integers, (or even four points) how can you be sure they are a rectangle? You only need two points (or four integers) to define a rectangle: Top Left corner position, and bottom right corner position (or a defined corner and a width / height pair). Your four points could describe a parallelogram, an eggtimer, or an irregular shape.
Do you need to check?
What should you do if it isn't?
Are they in order? If so, which way does it run - clockwise or anticlockwise?
If they are in order, is the first the TLHC? Or the TRHC? etc.
Is any of this going to affect the way you store things?
 
Share this answer
 
Comments
DaveyM69 8-Sep-10 8:02am    
Reason for my vote of 5
Good answer!
Estys 8-Sep-10 8:05am    
Actually, you need 2 points and a tilt angle to define a rectangle with sides not parallel to the coordinate system :-).
OriginalGriff 8-Sep-10 8:22am    
"Actually, you need 2 points and a tilt angle to define a rectangle with sides not parallel to the coordinate system :-). - Estys"
Smartarse! :laugh:
Toli Cuturicu 8-Sep-10 11:54am    
@Estys: Good point!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900