-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart_Vector.cpp
More file actions
63 lines (55 loc) · 816 Bytes
/
Cart_Vector.cpp
File metadata and controls
63 lines (55 loc) · 816 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
57
58
59
60
61
62
63
#include <iostream>
#include <cmath>
using namespace std;
#include "Cart_Vector.h"
//Constructors
Cart_Vector::Cart_Vector()
{
x = 0.0;
y = 0.0;
}
Cart_Vector::Cart_Vector(double inputx, double inputy)
{
x = inputx;
y = inputy;
}
//Overloaded Operators
Cart_Vector operator*(Cart_Vector v1, double d)
{
double x;
double y;
if (d == 0)
{
x = v1.x;
y = v1.y;
}
else
{
x = v1.x * d;
y = v1.y * d;
}
return Cart_Vector(x, y);
}
Cart_Vector operator / (Cart_Vector &v1, double d)
{
Cart_Vector* pvector = new Cart_Vector;
double x;
double y;
if (d == 0)
{
x = v1.x;
y = v1.y;
}
else
{
x = v1.x/d;
y = v1.y/d;
}
*pvector = Cart_Vector(x, y);
return *pvector;
}
ostream& operator << (ostream& os, Cart_Vector v1)
{
os << "<" << v1.x << ", " << v1.y << ">";
return os;
}