CS 1713, Introduction to Computer Science Assignment 4, Spring 1998 Equation of a line through two points Due February 12, 1998 The assignment: Write a C program to display the equation of the straight line through two points on the graph of an equation. The points are obtained by reading values of the x coordinates of the two points. The corresponding y coordinates are obtained from the function. Details of the C program: 1. Each line of input will contain two numbers representing the x coordinates x1, and x2 of two points on the graph of a function. The function used must be f(x) = x2-3x-2. You must implement the function f as a C function in the form: double f(double x) { /* code for f here */ } 2. The program should first print the coordinates of the two points in exactly the form Line through points: (2.10, -3.89), (-2.10, 8.71) Next (on a separate line) print out the equation of the line through the two points. The equation should be in the general form Y = m X + b, where m is the slope and b is the Y-intercept, both given with two decimal places. For full credit the equation should appear as you might expect to see it in a calculus book. (See Item 7 below.) 4. Keep reading pairs of numbers and printing out equations of lines until the two numbers read in are both 0.0. Then the program should terminate gracefully. 5. Your program should correctly handle any reasonable input. In particular it must deal with each of the following cases: · a line with a positive slope · a line with a negative slope · a horizontal line · two identical points (an error message, except for two zeros) 6. Your program should be well-documented and formatted. You should use indentation, blank lines, internal comments, meaningful identifiers, annotated identifiers, a consistent style, and header comments as in Assignment 1. 7. One of the challenging parts of this assignment is to write out the equation of the line in a ªniceº form, as you might see it in a calculus book. For full credit, you should conform to the following rules: · Except for the cases below, use the form ªY = 1.20X + 2.20º. · For a horizontal line, use the form ªY = 2.05º. · If the slope is exactly 1, use the form ªY = X + 1.05º. · If the slope is exactly ±1, use the form ªY = -X + 22.25º. · If b is exactly 0, use the form ªY = -2.22Xº. · In case b is negative, you should not write ªY = 2.10X + - 3.30º. · For extra credit, if m or b is an exact integer, write them without a decimal point. Details about creating and running the program: 1. Use the mkdir command to create a new directory named "assign4". Then use the cd command to change to this directory. All files related to this assignment should be in this directory. 2. Enter your C source program and call it "myline.c". 3. You should create and use a file named "makefile" as with assignment 2: myline: myline.c cc -o myline myline.c -lm lint: myline.c lint -m -u myline.c -lm 4. Check the program first with lint and then with the compiler, using the makefile. 5. Type the following data into a file named "linedata". Use redirection to direct this file into the line program as the standard input. 2.1 -2.1 0.5 3.75 1.0 3.0 1.0 -2.0 -2.0 4.0 2.0 2.0 0.0 4.0 -1.0 2.0 0.5 2.5 0.0 0.0 6. Use redirection or a script to turn in a source listing and a listing of a run of the program. 7. Here is what the output might look like. (Yours does not have to look exactly like this. In particular, this does the extra credit part.) Lines through x^2 - 3x - 2. Line through points: (2.10,-3.89),(-2.10,8.71) Equation of line: Y = -3X + 2.41 Line through points: (0.50,-3.25),(3.75,0.81) Equation of line: Y = 1.25X - 3.88 Line through points: (1.00,-4.00),(3.00,-2.00) Equation of line: Y = X - 5 Line through points: (1.00,-4.00),(-2.00,8.00) Equation of line: Y = -4X Line through points: (-2.00,8.00),(4.00,2.00) Equation of line: Y = -X + 6 Line through points: (2.00,-4.00),(2.00,-4.00) Identical points. There is no line. Line through points: (0.00,-2.00),(4.00,2.00) Equation of line: Y = X - 2 Line through points: (-1.00,2.00),(2.00,-4.00) Equation of line: Y = -2X Line through points: (0.50,-3.25),(2.50,-3.25) Equation of line: Y = -3.25