### not clear on the refrenced parameters

so far on my code i have the code for distance, slope, intercept , and line equation. i have to do a similar thing with intersection but the reference parameters are confusing me

my code so far
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158`` ``````#include #include #include #include #include "geometry.h" using std::string; using std::ostringstream; using std::setprecision; static ostringstream oss; string print_point(double x, double y) { oss << setprecision(2); oss.str(""); // Clear the output string oss << "(" << x << "," << y << ")"; return oss.str(); } double distance(double x1, double y1, double x2, double y2) { double x=x2-x1; double y=y2-y1; y=pow(y,2); x=pow(x,2); double d = sqrt(x+y); if ((x+y)<0) { oss << "distance has imaginary numbers."; } else { double d = sqrt(x+y); } return d; } bool equals(double a, double b) { return a == b || fabs(a - b) < 0.0001; } double slope(double x1, double y1, double x2, double y2) { double x=x2-x1; double y=y2-y1; double m =y/x; if (x=0) { m=HUGE_VAL; } return m; } double intercept(double x1, double y1, double x2, double y2) { double x=x2-x1; double y=y2-y1; double m =y/x; if (x==0) { m=HUGE_VAL; double b=x1; } else m=m*x1; double b = y1-m; return b; } string line_equation(double m, double b) { oss.str(""); // Clear the output string oss << setprecision(2); if (m==1 || m==-1 || m==0 || m==HUGE_VAL) { if (m==1) { if (b==0) { oss << "y = x "; } else if (b < 0) oss << "y = x - " << b*-1 ; else oss << "y = x + " << b; } if (m==-1) { if (b==0) { oss << "y = x "; } else if (b < 0) oss << "y = -x - " << b*-1; else oss << "y = -x + " << b ; } if (m==0) { if (b==0) { oss << "y = 0" ; } else if (b < 0) oss << "y = - " << b*-1 ; else oss<< " y = " << b; } if (m==HUGE_VAL) { if (b=0) oss << "x = 0"; else if (b>0) oss << " x = - " << b*-1; else oss << "x = " << b; } } else { if (b==0) oss << "y = x "; else if (b < 0) oss << "y = " << m << "x - " << b*-1 ; else oss << "y = " << m << "x + " << b ; } return oss.str(); } string line_equation(double x1, double y1, double x2, double y2) { return line_equation(slope(x1, y1, x2, y2), intercept(x1, y1, x2, y2)); } void intersection(double m1, double b1, double m2, double b2, double& i_x, double& i_y) { }``````

sorry its kinda long
What exactly do you not understand? The function takes 6 parameters, the first 4 are used to find the intersection, and next two hold the coordinates of the intersection you found.

 ``1234`` ``````//main file intersection(Var1,Var2,Var3,Var4,x_int,y_int) //var 1-4 are values you determined earlier in the function, x_int and y_int //hold the values that the function computes ``````

so instead of returning values int the function....

 ``12345678`` ``````void intersection(double m1, double b1, double m2, double b2, double& i_x, double& i_y) { int x_cord, y_cord; //do stuff.... i_x = x_cord; //simply set the reference values i_y = y_cord; }``````
Topic archived. No new replies allowed.