Question: Solve two problems using C programming language 1. Suppose that you are given the following code. #include typedef struct { double x; double y; }

Solve two problems using C programming language

1. Suppose that you are given the following code.

#include

typedef struct { double x; double y; } point;

int main(void) {

point test = {.25, .75};

pointshow(test);

return 0;

}

a.Write a function pointshow() so that the program is functionally equivalent to the three programs above.

b.Write a function pointdist() that computes the Euclidean distance between two points.

c.Write a function pointequal() that returns 1 if the two points are "equal"; and 0 otherwise. With floating point values it doesn't make much sense to test for exact equality; instead check to see if the distance between the points is less than 0.000001.

2.Define a data type rect for rectangles that are parallel to the axes in a Cartesian coordinate system. Represent a rectangle by its lower left and upper right endpoints using the point data type above.

a.Write a function that computes the area of a rectangle.

b.Write a function that returns 1 if a point falls within a rectangle, 0 otherwise. Use the point and rect data types above.

c.Write a function that returns 1 if the first rectangle is completely contained inside the second rectangle, and 0 otherwise.

Hint: check if the lower left and upper right endpoints of the first rectangle fall within the second rectangle.

d.Write a program that reads in a list of points (given by their x and y coordinates) and determines the pair that is the farthest apart.

Hint: store the points in an array and use the pointdist()function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!