cpp1_code_f06 - USERNAME NAME 1 Write a function to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
USERNAME ___________________ NAME __________________________________ 1. Write a function to calculate the distance from a point to a line. The formula describing the line is: 0 = + + C By Ax . If the coordinates of the point P are ( 0 x , 0 y ), the distance d from the point P to the line can be calculated by: 2 2 0 0 B A C By Ax d + + + = . The function prototype is given by: double distance ( double A, double B, double C, double x0, double y0); The function calculates and returns the distance from ( x0 , y0 ) to the line described by coefficients A , B and C . Example: The distance from (-2, 1.5) to the line described by 0 4 5 . 3 2 = - + y x is found by: dist = distance(2, 3.5, -4, -2, 1.5); --------------------------------------------- Your Solution -------------------------------------------- double distance( double A, double B, double C, double x0, double y0) { return fabs(A*x0+B*y0+C)/sqrt(pow(A,2)+pow(B,2)); }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
USERNAME __________________ NAME_________________________________ 2. Write a function that determines whether three numbers (a, b, c) constitute a triangle. If
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

cpp1_code_f06 - USERNAME NAME 1 Write a function to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online