-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
executable file
·160 lines (128 loc) · 2.92 KB
/
vector.cpp
File metadata and controls
executable file
·160 lines (128 loc) · 2.92 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include<iostream>
#include<cstdarg>
#include<cmath>
#include"vector.h"
#include"numberbase.h"
using namespace std;
/*
//aVector accepts an array as input, thereby
//allowing for the creation of vectors with multiple directions.
class aVector {
private:
int v[];
int size;
public:
//Paramaterised constructor
aVector(int a[]) {
size = a.size()
for(int ii = 0, ii < size; ii++) {
v[ii] = a[ii];
}
}
//Default constructor
aVector() {
int a[3] = {0,0,0};
new (this) aVector(a);
}
//Copy Constructor
aVector(const aVector& original) {
v = (original.v);
size = (original.size);
}
};
//variableVector uses a variadic function to allow for
//the construction of vectors with multiple directions.
class variableVector {
private:
double v[];
int size;
public:
variableVector(int size ,double n, ...) {
va_list args;
va_start(args, size);
for (int i = 0; i < size; i++) {
v[i] = va_arg(args, double);
}
va_end(args);
}
};
*/
//myVector is a standard vector object in 3 space.
//Parameterized Constructor
myVector::myVector(int x, int y, int z):NumberBase("Richard Rohrkemper"){
i = x;
j = y;
k = z;
}
//Default Constructor
myVector::myVector() {
new (this) myVector(0,0,0);
}
//Copy Constructor
myVector::myVector(const myVector& original) {
i = (original.i);
j = (original.j);
k = (original.k);
}
//Destructor
myVector::~myVector() {
}
//Accesor methods
int myVector::getI() {
return i;
}
int myVector::getJ() {
return j;
}
int myVector::getK() {
return k;
}
void myVector::setI(int n) {
this->i = n;
}
void myVector::setJ(int n) {
this->j = n;
}
void myVector::setK(int n) {
this->k = n;
}
//Override the + operator
myVector* myVector::operator+ (int n) {
this->i = this->i + n;
this->j = this->j + n;
this->k = this->k + n;
return (this);
}
//Override the * operator
myVector* myVector::operator* (int n) {
this->i = this->i * n;
this->j = this->j * n;
this->k = this->k * n;
return (this);
}
//Override the - operator
myVector* myVector::operator- (int n) {
this->i = this->i - n;
this->j = this->j - n;
this->k = this->k - n;
return (this);
}
//basic print for testing
void myVector::print() {
cout << "<" << this->getI() << "," << this->getJ() << "," << this->getK()
<< ">" << endl;
}
void myVector::demo() {
myVector v1(1,-2,3);
cout << "Lets create a vector." << endl;
v1.print();
cout << "Lets add 3 to that vector." << endl;
v1 + 3;
v1.print();
cout << "Lets multiply that vector by 3." << endl;
v1 * 3;
v1.print();
cout << "Lets subtract three from that vector." << endl;
v1 - 3;
v1.print();
}