-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch7 실습문제 7.cpp
68 lines (56 loc) · 1.11 KB
/
ch7 실습문제 7.cpp
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
#include <iostream>
#include <string>
using namespace std;
class Matrix
{
int array[4];
public:
Matrix() { array[0] = array[1] = array[2] = array[3] = 0; }
Matrix(int a, int b, int c, int d) { array[0] = a, array[1] = b, array[2] = c, array[3] = d; }
void show();
/*
Matrix operator+ (Matrix x);
Matrix& operator+= (Matrix x);
bool operator== (Matrix x);*/
void operator>> (int x[]);
};
/*
Matrix Matrix::operator+ (Matrix x)
{
Matrix temp;
for (int i = 0; i < 4; i++)
temp.array[i] = this->array[i] + x.array[i];
return temp;
}
Matrix& Matrix::operator+=(Matrix x)
{
for (int i = 0; i < 4; i++)
this->array[i] += x.array[i];
return *this;
}
bool Matrix::operator==(Matrix x)
{
for (int i = 0; i < 4; i++)
{
if (this->array[i] != x.array[i])
return false;
}
return true;
}*/
void Matrix::operator>> (int x[])
{
for (int i = 0; i < 4; i++)
this->array[i] = x[i];
}
void Matrix::show()
{
cout << "Matrix = {";
cout << array[0] << ' ' << array[1] << ' ' << array[2] << ' ' << array[3] << " }" << endl;
}
int main()
{
Matrix a(4, 3, 2, 1), b;
int x[4], y[4] = { 1,2,3,4 };
a >> x;
a.show();
}