c programing homework
Page 1 of 2
CEG 2170
Laboratory 9 1. A point in a plane can be represented by two coordinates, x and y. We can represent a point in a plane by
a data type named POINT, using a structure having two fields as shown:
typedef struct
{
int x;
int y;
}POINT;
Write a program that determines whether a variable of type POINT is located in the right half of the x-y
plane (x > 0), or not. The program should prompt the user to enter point data from the keyboard, and should
use a function that accepts a structure representing a point and returns true or false, based on where the point
is located.
2. Modify the program to include a second structure that models a line, which consists of two points,
using the structure definition as shown:
typedef struct
{
POINT start;
POINT end;
}LINE;
Write a function that accepts a structure of type LINE and returns the length of the line. Read in data for two
points from the keyboard, and test this function.
Page 2 of 2
3. Write a program that will create an array of line structures. The data for each line will be in a file named
linedata.txt in the following format:
N //number of lines in the file
Xstart
….
Ystart Xend Yend //integer starting and ending points of line 1
Xstart Ystart Xend Yend //integer starting and ending points of line N
a. Read the number of lines, N
b. Create an array of LINE’s with N elements
c. Print the array data to the screen.
d. Use qSort to sort the array by line length. e. Print the sorted array to the screen.
Run your code again using the input file linedata1.txt. You should not need to modify your
program in any way.