-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharr.cpp
More file actions
116 lines (101 loc) · 1.64 KB
/
Copy patharr.cpp
File metadata and controls
116 lines (101 loc) · 1.64 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
#include<iostream>
using namespace std;
template<class t>
class array
{
private:
int m;
int len;
t *element;
public:
array(){}
array(int s)
{
m=s;
len=0;
element=new t [m];
}
array(array<t> &b)
{
element=new t [5];
for(int i=0;i<5;i++)
element[i]=b.element[i];
}
void setdata(t a[]);
array<t> operator-(array<t>);
array<t> operator+(array<t>);
array<t> operator!();
array<t> operator*(t);
void operator+=(t);
void display();
};
template<class t>
array<t> array<t>::operator+(array<t> k)
{
array<t> b(5);
for(int i=0;i<5;i++)
b.element[i]=k.element[i]+element[i];
return b;
}
template<class t>
array<t> array<t>::operator-(array<t> k)
{
array<t> b(5);
for(int i=0;i<5;i++)
b.element[i]= -k.element[i]+element[i];
return b;
}
template<class t>
array<t> array<t>::operator!()
{
array<t> b(5);
for(int i=0;i<5;i++)
b.element[i]=-element[i];
return b;
}
template<class t>
array<t> array<t>::operator*(t b)
{
array k(5);
for(int i=0;i<5;i++)
k.element[i]=element[i]*b;
return k;
}
template<class t>
void array<t>::operator+=(t b)
{
for(int i=0;i<5;i++)
element[i]+=b;
}
template<class t>
void array<t>::display()
{
cout<<"\nafter calculation:";
for(int i=0;i<5;i++)
cout<<element[i]<<"\t";
}
template<class t>
void array<t>::setdata(t a[5])
{
for(int i=0;i<5;i++)
element[i]=a[i];
}
int main()
{
array<int> arr1(5);
int x[5]={10,15,16,19,25};
arr1.setdata(x);
array<int> arr2(arr1);
arr1.display();
array <int> res(5);
res=arr1+arr2;
res.display();
res=arr1-arr2;
res.display();
res=!arr1;
res.display();
res=arr1*3;
res.display();
arr2+=10;
arr2.display();
}