-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-8.cpp
More file actions
54 lines (43 loc) · 827 Bytes
/
task-8.cpp
File metadata and controls
54 lines (43 loc) · 827 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
#include <iostream>
class Vector3d
{
private:
double m_x, m_y, m_z;
public:
Vector3d(double x = 0.0, double y = 0.0, double z = 0.0) : m_x(x), m_y(y), m_z(z)
{
}
void print()
{
std::cout << "Vector(" << m_x << ", " << m_y << ", " << m_z << ")" << std::endl;
}
friend class Point3d; /* now friend class of Vector3d */
};
class Point3d
{
private:
double m_x, m_y, m_z;
public:
Point3d(double x = 0.0, double y = 0.0, double z = 0.0) : m_x(x), m_y(y), m_z(z)
{
}
void print()
{
std::cout << "Point(" << m_x << ", " << m_y << ", " << m_z << ")" << std::endl;
}
void moveByVector(Vector3d &v)
{
m_x += v.m_x;
m_y += v.m_y;
m_z += v.m_z;
}
};
int main()
{
Point3d p(2.0, 1.0, 5.5);
Vector3d v(3.0, 4.0, -4.25);
p.print();
p.moveByVector(v);
p.print();
return 0;
}