Question
Please answer in c language(not cpp nor c sharp). The way for reading input is fscanf to read from the file. But you also can
Please answer in c language(not cpp nor c sharp). The way for reading input is fscanf to read from the file. But you also can use scanf if you think it is more convenient.
The makefile(you can ignore this if you not using linux system): part4: gcc -o part4 lab3-q4.c -lm
The command for linux(or you can use other way to run the program): gcc -o part4 lab3-q4.c -lm ./part4 lab3-q4-tc1.in lab3-q4-tc1.ans The file "lab3-q4.c":
#include
typedef struct point { int x, y; double slope; } Point;
int isConvex(Point p1, Point p2, Point p3) { /* if collinear, return 0 */ if ((p2.y-p1.y)*(p3.x-p2.x) == (p3.y-p2.y)*(p2.x-p1.x)) { return 0; } /* if convex, return 1 */ if ((p2.x-p1.x)*(p3.y-p2.y) > (p3.x-p2.x)*(p2.y-p1.y)) { return 1; } /* return 0 (i.e. concave) */ return 0; }
int main (int argc, char *argv[]){ // Your code here return 0; } The file "lab3-q4-tc1.in": 4 0 0 1 10 5 5 10 1 If the code can pass tc1, the output of "lab3-q4-tc1.ans" should be: 0 0 10 1 1 10
You are given a list of points. You are asked to identify the subset of points constructing the convex polygon. Your program should read the input from the file, and output the answer to another file. The first argument is the input file name, while the second argument is the output file name. Name your program as "lab3-q4.c". Hint: This question involves the techniques (i) sorting, (ii) stack and (iii) 2-d geometry. Input file: First line, n100, an integer indicating the number of points on the coordinate plane. Following n lines, each line consists of 2 integers, xy, indicating the coordinate of a point. You can safely assume that (0,0) must be the first point. Besides (0,0), the x-coordinate and y-coordinate are all positive. Qutput file: k lines of points, each line consists of 2 integers, xy, which indicate a k-sided convex polygon. The first point must be (0,0), and you should output the point in the anti-clockwise direction of the convex polygon. If points p1, p2, p3 are collinear and on the edge of a convex polygon, you should only output the two verticesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started