
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Assignment; Class: Intro to Computer Program II; Subject: Computer Science; University: University of Texas - San Antonio; Term: Spring 1998;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!
/* Name:
Neal R. Wagner, Course Instructor
Due Feb 14, 1997
CS 1713 Section 02
Print the equation of a line through
two points on the graph of an equation.
Read x-coordinates x1 and x2.
Calculate the corresp. y-coords y1 and y
on the graph of equation y = x^2 - 3x - 2.
Calculate the slope m and the y-intercept b.
Use m and b to print the line’s equation.
Print integers without a decimal point.
Keep reading pairs of x-coords up to zeros.
Unless the x-coords are the same, print the
line in as in a calculus book.
{ void main(void)void printline(double x1, double y1, double x2, double y2);void printnum(double z);double f(double x);#include <math.h>#include <stdio.h>/ for (;;) {printf("Lines through x^2 - 3x - 2.\n");double x1, y1, x2, y2; / coords of two points */ printf("\n\n");printline(x1, y1, x2, y2);y1 = f(x1); y2 = f(x2);if (x1 == 0.0 && x2 == 0.0) break;scanf("%lf %lf", &x1, &x2);
printline(1.0, 0.0, 3.0, 0.0); printf("\n");printline(2.0, 3.0, 2.0, 4.0); printf("\n");printf("Other lines:\n");}
{ double f(double x)/* f: function on which the points occur. /} return xx - 3.0*x -2;
{ void printnum(double z)/* it is an exact integer,// print num: Print a double with two decimals unless */} if ( ((int) z) == z) printf("%1.0f", z);
else printf("%3.2f", z);
/* with y1 and y2 the corresponding y-coordinates./* x1 and x2 are input x-coordinates of two points, // printline: Print a line as in a calculus book. */}
{void printline(double x1, double y1, double x2, double y2) if (x1 == x2) {printf("(%3.2f,%3.2f),(%3.2f,%3.2f)\n", x1, y1, x2, y2);printf("Line through points: ");double m, b;
if (y1 == y2) printf("Identical
(^) points.
There
(^) is (^) no (^) line.");
else { printf("Equation
(^) of (^) line:
printnum(x1);
return;}
m = (y1 - y2)/(x1}
(^) x2);
(^) b (^) = (^) -m*x
(^) y1;
printf("Equation
(^) of (^) line:
(^) Y (^) = (^) ");
/* handle case of
(^) no (^) X (^) term
(^) here,
(^) i.e.,
(^) m (^) == (^) 0. (^) */
/* This includes
(^) the (^) case
(^) m (^) == (^0) && (^) b (^) == (^) 0. (^) */
if (m == 0.0) { return;printnum(b);
/* Print the X term,}
(^) assuming
(^) m (^) != (^) 0. (^) */
if (m == 1.0) printf("X ");
else if (m == -1.0) printf("-X ");
else { printnum(m); printf("X
/* Print constant}
(^) term.
Note:
(^) if (^) b (^) == (^) 0, (^) print
nothing (works
(^) because
(^) m (^) != (^0) (^) here).
if (b < 0.0) { printf("- ");
(^) printnum(fabs(b));
else if (b > 0.0)}
printf("+ ");
(^) printnum(b);
Lines through x^2 -}
(^) 3x (^) - (^) 2.
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:
Identical points.
There
(^) is (^) no (^) line.
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:
Equation of line: Y
Line through points:Other lines:
Equation of line: X
Line through points:
Equation of line: Y