-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cpp (Fixed)
More file actions
74 lines (66 loc) · 1022 Bytes
/
Vector.cpp (Fixed)
File metadata and controls
74 lines (66 loc) · 1022 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
64
65
66
67
68
69
70
71
72
73
74
#include "stdafx.h"
#include "iostream"
#include "Vector.h"
Vector::Vector()
{
this->size = 0;
this->mas = nullptr;
}
Vector::Vector(double* mas_src, int n)
{
this->size = n;
this->mas = new double[n];
for (int i = 0; i < n; i++)
{
this->mas[i] = mas_src[i];
}
}
Vector::~Vector()
{
delete[] this->mas;
}
double Vector::operator[](size_t position)
{
if (position > this->size)
{
return 0;
}
else
{
return this->mas[position];
}
}
double *Vector:: operator=(const Vector& object)
{
if (this->mas != nullptr)
{
delete[] this->mas;
}
this->size = object.size;
this->mas = new double[object.size];
for (int i = 0; i < object.size; i++)
{
this->mas[i] = object.mas[i];
}
return this->mas;
}
double * operator+(const Vector& a, double *b)
{
if (a.mas == nullptr && b == nullptr)
{
return 0;
}
else if (a.mas == nullptr)
{
return b;
}
else if (b == nullptr)
{
return a.mas;
}
for (int i = 0; i < a.size; i++)
{
a.mas[i] = a.mas[i] + b[i];
}
return a.mas;
}