-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline.cpp
More file actions
56 lines (50 loc) · 979 Bytes
/
line.cpp
File metadata and controls
56 lines (50 loc) · 979 Bytes
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
#include <iostream>
using namespace std;
class Point
{
private:
double m_x,m_y;
public:
Point(double x = 0, double y = 0) : m_x(x),m_y(y) {}
double getX() { return m_x; }
double getY() { return m_y; }
void print();
};
class Line
{
private:
double m_a,m_b;
public:
Line(double a, double b) : m_a(a),m_b(b) {}
double getA() { return m_a; }
double getB() { return m_b; }
void print();
friend Point setpoint(Line & m, Line & n);
};
int main(void)
{
double a1,b1,a2,b2;
cout << "please enter a1,b1,a2,b2\n";
cin >> a1 >> b1 >> a2 >> b2;
Line l1 = Line(a1,b1);
l1.print();
Line l2 = Line(a2,b2);
l2.print();
Point result = setpoint(l1,l2);
result.print();
return 0;
}
void Point::print()
{
cout << "(" << m_x << "," << m_y << ")" << endl;
}
void Line::print()
{
cout << "y=" << m_a << "x+" << m_b << endl;
}
Point setpoint(Line & m, Line & n)
{
double x = (n.getB()-m.getB())/(m.getA()-n.getA());
double y = m.getA()*x+m.getB();
return (Point(x,y));
}