我正在做一个任务,我必须为用户创建一个程序来输入矩形的坐标。
该程序旨在成为结构中的结构。
如果无效,我必须输出一条错误消息并让用户无限期地重试,直到用户正确为止。
程序会反复询问用户一个点的坐标,当用户分别为 x 和 y 输入 0 和 0 时,程序将退出。
程序必须说明点是在矩形的内部还是外部,并打印出内部的点。我还需要弄清楚将 main 函数放在哪里,以及在其中放置什么。谢谢。
这是我的代码:
#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;
}
int main(){
/* calls goes here */
return 0;
}
编辑:我添加了 main,但我不知道如何调用函数。