Creating a program to find value in rectangle

I am working on an assignment where I have to create a program for users to input coordinates for a rectangle.

This program is intended to be a struct within a struct.

If invalid, I have to output an error message and let user try again, indefinitely, until the user gets it right.

The program should repeatedly ask users for coordinates of a point, and the program will quit when user enters 0 and 0 for x and y respectively.

The program has to say whether the point is inside of outside the rectangle. I also need to figure out where to put the main function, and what to put in it. Please let me know how exactly to complete this program, and I need to know ASAP. The program is due TONIGHT.

Here is my code:


Code:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>


typedef struct
{
int x;
int y;
} point_t;

typedef struct
{
point_t upper_left;
point_t lower_right;
} rectangle_t;


int is_inside (point_t* pPoint, rectangle_t* pRect)
{
return ((pPoint->x >= pRect->upper_left.x ) &&
(pPoint->x <= pRect->lower_right.x) &&
(pPoint->y >= pRect->upper_left.y ) &&
(pPoint->y <= pRect->lower_right.y));

}

point_t get_point(char* prompt)
{
point_t pt;
printf("Given a rectangle with a side parallel to the x axis and a series of points on the xy plane this program will say where each point lies in relation to the rectangle. It considers a point on the boundary of the rectangle to be inside the rectangle\n");
printf ("Enter coordinates for the upper left corner\n");
printf ("X: ");
scanf ("%d", &pt.x);
printf ("Y: ");
scanf ("%d", &pt.y);

return pt;
}

rectangle_t get_rect(char* prompt)
{
rectangle_t rect;
printf (prompt);
rect.upper_left = get_point("Upper left corner: \n");
rect.lower_right = get_point("Lower right corner: \n");

return rect;
}
the program is very much complete.. just create a main like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
rectangle_t rect = get_rect("Enter rectangle co-ordinates");

point_t point_check = get_point("Enter points to check");

if(is_inside(&point_check, &rect))
cout << "Its inside" << endl;
else
cout << "Its outside";

return 1;
}


a couple of points:
1. put you code in code blocks.
2. if you are not changing anything in a function the you can just send the parameters by value also. like in is_inside there is no need to send it as pointer.
3. when values are not changed put a const, this will help compiler in optimization and tells the user also that this value will not change.
Topic archived. No new replies allowed.