Home Forums C Programming Exercise regarding Structures : Need help

Viewing 0 reply threads
  • Author
    Posts
    • #2123
      shubham123
      Participant
      Hello guys, I’m new here.

      I’m a Computer Science college freshman and we have an exercise about structures, here are the instructions:

      Exercise on structures: CHAPTER 8
      Deadline on Aug 16, 2008 (until 11:59pm)

      Define a structure for a rectangle in the cartesian plane whose sides lay parallel to the x- and y- axes, as well as for a point in the same plane (which the rectangle may reuse). Afterwards, define separate functions that take &&&references&&& to such rectangles and then return the following:

      – is it a valid rectangle? (0 if not, any other integer if it is) – midpoint (returns a Point)
      – area (returns a float/double)
      – perimeter (returns a float/double)

      Define a function that accepts two references to rectangles as parameters, and returns 0 if they don’t overlap, or any other integer if they do.

      The driver program must behave similar to the following: %% Provide the x and y coordinates of the lower-left vertex: -12 78 %% (-12,78) defined for lower left vertex. %% … the other vertex is entered

      %% Here are the points you’ve defined. %%
      (-12,78) : lower left corner (?) <<<--- verify %% (1,16) : upper right corner (?)%% The points you’ve entered doesn’t appear to belong to a valid rectangle. Enter another? (Y/N): Y%% … the vertices are once again requested
      %% Here are the points you’ve defined. %%
      (1,2) : lower left corner %%
      (5,3) : upper right corner %%

      Here are some statistics regarding your rectangle:
      %% The midpoint is at: (3.0,2.5)
      %% The area is: 4.0 sq. units %% The perimeter is: 8.0 units
      %% This is the first rectangle you’ve defined. If you define another, then we can test whether the two overlap. %% Enter another? (Y/N): Y
      %% … define another rect %% … the stats are displayed
      %% … (if you have already entered at least two valid rectangles, then the program will tell if the last two did overlap.)
      %% … (for example: This rectangle overlaps with the last rectangle, whose lower-left vectex is at (x1,y1) and upper-right vertex is at (x2,y2) )
      %% … ask whether the user wants to enter another or not
      %% … (and so on.) NOTES: the functions should only accept the values inputted through the parameters. Don’t ask for input inside their bodies. That’s the driver’s job.

      I’ve already completed the program and I think I did it right. But I have a problem because it doesn’t go to the fuction that checks if the two rectangles entered overlap. overlap() :chomp:

      and i have another problem, when the user inputs points for the second time and so on, it still displays the statistics (median, perimeter and area) even though the points are invalid. :confused:

      here’s my code:

      This is due tomorrow night. i’d really appreciate your prompt response. :D

      here’s my YM:hautehavoc
      gtalk:jenielle.gabriel

Viewing 0 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.