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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#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.

1
2
3
4
//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....

1
2
3
4
5
6
7
8
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.