-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector2D.cpp
More file actions
54 lines (43 loc) · 808 Bytes
/
Vector2D.cpp
File metadata and controls
54 lines (43 loc) · 808 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
#include <iostream>
#include "Vector2D.h"
#include "Point2D.h"
using namespace std;
//VECTOR2D.CPP
//default constructor
Vector2D::Vector2D()
{
x = 0.0;
y = 0.0;
}
//user-set constructor
Vector2D::Vector2D(double in_x, double in_y)
{
x = in_x;
y = in_y;
}
//non-member overloaded operator for <<
ostream& operator << (ostream& os, const Vector2D& v)
{
os << "<" << v.x << ", " << v.y << ">" << endl;
return os;
}
//non-member overloaded operator for *
Vector2D operator * (Vector2D v, double z)
{
Vector2D temp;
temp.x = (v.x * z);
temp.y = (v.y * z);
return temp;
}
//non-member overloaded operator for /
Vector2D operator / (Vector2D v, double z)
{
if (z == 0)
{
return v;
}
Vector2D temp;
temp.x = (v.x / z);
temp.y = (v.y / z);
return temp;
}