Struct Program to find Point in Rectangle

This is a discussion on Struct Program to find Point in Rectangle within the C++ Programming forums, part of the General Programming Boards category; I am working on an assignment where I have to create a program for users to input coordinates for a ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Struct Program to find Point 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;
    }

  2. #2
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Quote Originally Posted by DMJKobam View Post
    I also need to figure out where to put the main function...
    After the function definitions...

    Quote Originally Posted by DMJKobam View Post
    ...and what to put in it.
    Function calls...


    It looks like most of the work is done, and you just have to call the functions. I suspect these functions were already provided for you, and you just had to create main. If you have problems writing main, post what you've done and someone could probably help. However, it seems you didn't leave yourself enough time for this.
    IDE - Visual Studio 2005
    Windows XP Pro

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Functions where not provided

    The functions where not provided. I am trying to figure out to how to call them. I have to submit this in an hour.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. more with my 1st structure program
    By sballew in forum C Programming
    Replies: 42
    Last Post: 10-22-2001, 08:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21