Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

First define a structure (using two numbers) to represent a point in two dimensi

ID: 3546147 • Letter: F

Question

First define a structure (using two numbers) to represent a point in two dimensional co-ordinate plane. A rectangle in the two dimensional plane can be specified by four two dimensional points representing the four corners. Define a structure for this representation of a rectangle. The structure should use the point structure defined earlier. Also, assume the sides of a rectangle to be parallel to the X and Y axes.

i) Write a function that, upon input a structure of the above kind, determines whether the structure represents a valid axis parallel rectangle.
ii) Write a function that, upon input a valid rectangle, determines the area of the rectangle.
iii) Write a function that, upon input a valid rectangle and a point p, determines whether the point p lies inside, on or outside the rectangle.

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

typedef struct point

{

int x;

int y;

} pt ;

typedef struct rect

{

pt p1;

pt p2;

pt p3;

pt p4;

} rt ;


int main()

{

rt a ;

printf("enter the first point");

scanf("%d %d",&a.p1.x,&a.p1.y);

printf("enter the second point");

scanf("%d %d",&a.p2.x,&a.p2.y);

printf("enter the third point");

scanf("%d %d",&a.p3.x,&a.p3.y);

printf("enter the fourth point");

scanf("%d %d",&a.p4.x,&a.p4.y);

if((a.p1.x==a.p4.x)&&(a.p2.x==a.p3.x)&&(a.p1.y==a.p2.y)&&(a.p3.y==a.p4.y))

{

printf("it is a valid axis parllel rectangle");

printf("area of rectangle is %d",(a.p2.x-a.p1.x)*(a.p4.y-a.p1.y));

}

else

printf("it is not a axis parllel rectangle");

}