Term Project
Term Project
A land is defined by n points that are connected to form a closed polygon as shown below. The area A of the land can be computed as
1 A 2
Y (x5, y5)
n2 i 0
xi 1 xi yi 1 yi
(x1, y1)
Notice that although the illustrated polygon has only six distinct corners, n for this polygon is 7 (i.e., n = no. of corners + 1) because the above equation expects that the last point, (x6, y6), will be a repeat of the initial point, (x0, y0). The price of the one square meter of the land is calculated based on its area according to the following table: Area (m2) Price (Dhs/m2) 0.0 499.99 3000.0 500.0 1999.99 3500.0 2000.0 3999.99 4000.0 4000.0 and above 5000.0
Write a C-Program that calculates the area and price of any land defined by its corners. Represent the (x, y) coordinates of the connected points as two arrays x[ ] and y[ ] of at most 20 type double values. The main( ) function should get the number of corner points from the user. If the value of n (n = no. of corners + 1) exceeds the size of the x[ ] and y[ ] arrays, or n is less than 4, the program should be terminated.
Your C-program SHOULD contain and use the following functions: get_corners: o takes as parameters n, and two arrays x[ ] and y[ ] o gets the series of x[ ] and y[ ] from the user o If the first coordinates (x0, y0) are not the same as the last coordinates (xn, yn), exit the program o fills the arrays x[ ] and y[ ] with data o returns void output_corners: o takes as parameters n, and two arrays x[ ] and y[ ] o print on the screen the x and y coordinates organized in a table o returns void
polygon_area: o takes as n, and two arrays, x[ ] and y[ ] o returns as the value of the area of the closed polygon.
polygon_price: o takes as parameter the area of the polygon o returns as the value of the price in Dhs of the closed polygon.
Notes: To terminated the C-Program at from anywhere in the C-code use exit( ); To test your program, use the following data set, which defines a polygon whose area is 8550.0 m2 and price is 42,750,000.0 Dhs.
x (km) y (km)
40.0 0.0
40.0 75.0
70.0 75.0
70.0 30.0
90.0 0.0
70.0 0.0
40.0 0.0
Sample input/output
Enter Enter Enter Enter Enter Enter Enter Enter number (x, y) (x, y) (x, y) (x, y) (x, y) (x, y) (x, y) of corner for point for point for point for point for point for point for point points: 6 0: 40 0 1: 40 75 2: 70 75 3: 70 30 4: 90 0 5: 70 0 6: 40 0
x(m) y(m) ----------------------40.000 0.000 40.000 75.000 70.000 75.000 70.000 30.000 90.000 0.000 70.000 0.000 40.000 0.000 ----------------------Area = 2550.000000 m2, Price = 10,200,000.0 Dhs