-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart_Vector.cpp
More file actions
43 lines (38 loc) · 927 Bytes
/
Cart_Vector.cpp
File metadata and controls
43 lines (38 loc) · 927 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
#include <iostream>
#include <cmath>
#include "Cart_Vector.h"
using namespace std;
//generates a cart vector of default 0,0
Cart_Vector::Cart_Vector()
{
x=0.0;
y=0.0;
}
//generates a cart vector of the user's choice
Cart_Vector::Cart_Vector(double inputx, double inputy)
{
x=inputx;
y=inputy;
}
//allows cart vectors to be divided by a scalar double
Cart_Vector operator /(Cart_Vector C1, double d)
{
Cart_Vector tempx, tempy;
tempx.x= C1.x/d;
tempy.y= C1.y/d;
return Cart_Vector(tempx.x, tempy.y);
}
//allows cart vectors to be multiplied by a scalar double
Cart_Vector operator *(Cart_Vector C1, double d)
{
Cart_Vector tempx, tempy;
tempx.x= C1.x*d;
tempy.y= C1.y*d;
return Cart_Vector(tempx.x, tempy.y);
}
//overloads the stream operator to have cart vectors be input as < <x,y> >
ostream &operator << (ostream &out, const Cart_Vector &Cart_Vector)
{
out<< "<"<< Cart_Vector.x<<","<< Cart_Vector.y<<">";
return out;
}