Solutions will be judged on


Question 1

 

Write a C program to find the area of a polygon from the coordinates of its vertices.

Input is to be read from a text file. The program should take the name of the file as a command line input.

Each row in the input contains x and y coordinates of a vertex.

Example: input1.txt represents a polygon with five vertices and area 0.2558

 

 Figure 1

 

The above figure is only an example. The code will be tested with various inputs.

There is no upper limit on the number of vertices (Do not use fixed size arrays).

Hint: In example of figure 1, area of polygon is sum of areas of triangles A1A2A3, A1A3A4, A1A4A5

 

Question 2

 

Write a C program to verify whether a given sequence of points can successfully form a polygon or not. A sequence of points forms a polygon if none of the edges are intersecting.

Input is to be read from a text file. The program should take the name of the file as a command line input.

Each row in the input contains x and y coordinates of a vertex.

Example1: The sequence of points in figure 1 (in the previous question) successfully forms a polygon

Example2: The sequence of points A1, A2… A5 in figure 2 do not form a polygon because edges A2A3 and A1A5 are intersecting. Input for figure 2 can be read from input2.txt

 

Figure 2

 

The above figures are only examples. The code will be tested with various inputs.

There is no upper limit on the number of vertices (Do not use fixed size arrays).

The program should display “Polygon formed” or “Polygon not formed” on the screen based on the result.