|
|
CS 2073, Fall 2005
Program 3
Equations of a Line
Week 3: Sep 7-9
Due (on time):
2005-09-19 23:59:59
Due (late):
2005-09-21 23:59:59
|
Program 3 must be emailed to:
nrwagner@cs.utsa.edu
following directions for: running
and submitting a C program, with deadlines:
- 2005-09-19 23:59:59 (that's Monday, 19 September 2005, 11:59:59 pm)
for full credit.
- 2005-09-21 23:59:59 (that's Wednesday, 21 September 2005, 11:59:59 pm)
for 75% credit.
|
Special Note: Initial deadline has
been pushed off until Monday, 19 Sept. 2005, 11:59:59 pm.
Introduction:
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 about what to do:
- Each successive pair of input numbers will
represent 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 to calculate value and return it here */
}
- 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 6 below.)
- 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.
- 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)
- Your program should be well-documented and formatted. You should use in
dentation, blank lines, internal comments, meaningful identifiers,
annotated identifiers, a consistent
style, and header comments as in Assignment 1.
- 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:
| i. | Except for the cases below, use the form: |
Y = 1.20X + 2.20. |
| ii. | For a horizontal line, use the form: |
Y = 2.05. |
| iii. | If the slope is exactly 1, use the form: |
Y = X + 1.05. |
| iv. | If the slope is exactly -1, use the form: |
Y = -X + 22.25. |
| v. | If b is exactly
0, use the form: |
Y = -2.22X. |
| vi. | In case b is negative, you should
not write: |
Y = 2.10X + - 3.30. |
| vii. | For extra credit, if m or b
is an exact integer, | write them without a decimal point. |
Sample input:
Here is sample data for your program. For convenience with the use
of Visual Studio, use the following file which has these numbers with no
line breaks: lines.dat.
Then just copy it all into the terminal window.
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
Sample output:
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
What you should email:
Refer to the submissions directions and to
deadlines at the top of this page. The text file that you submit
should first have Your Name, the Course Number,
and the Program Number. The rest of the file
should have the following in it, in the order below, and clearly labeled,
including at the beginning the appropriate item letters:
a, b, c, etc.
|
Contents of email submission
for Program 3:
Last Name, First Name; Course Number; Program Number.
- C source for your program, quadratic.c. (Or whatever you wish to name it.)
- Results of a run or runs of the program, including at least all the 8 sets of
data above.
|
Revision date: 2005-09-05.
(Please use ISO
8601, the International Standard.)