AP6_(1).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
#include <iostream>
using namespace std;
 
class Matrix {
    int a1, a2, a3, a4;
public:
    Matrix() {}
    Matrix(int a1, int a2, int a3, int a4) { this->a1 = a1; this->a2 = a2; this->a3 = a3; this->a4 = a4; }
    void show() { cout << "Matrix = { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << " }" << '\n'; }
    void operator>>(int x[]);
    void operator<<(int y[]);
};
 
void Matrix::operator>>(int x[]) {
    x[0= a1;
    x[1= a2;
    x[2= a3;
    x[3= a4;
}
 
void Matrix::operator<<(int y[]) {
    a1 = y[0];
    a2 = y[1];
    a3 = y[2];
    a4 = y[3];
}
 
int main() {
    Matrix a(4321), b;
    int x[4], y[4= { 1,2,3,4 };
    a >> x;
    b << y;
 
    for (int i = 0; i < 4; i++cout << x[i] << ' ';
    cout << '\n';
    b.show();
}
cs

AP6_(2).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
#include <iostream>
using namespace std;
 
class Matrix {
    int a1, a2, a3, a4;
public:
    Matrix() {}
    Matrix(int a1, int a2, int a3, int a4) { this->a1 = a1; this->a2 = a2; this->a3 = a3; this->a4 = a4; }
    void show() { cout << "Matrix = { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << " }" << '\n'; }
    friend void operator>>(Matrix a, int x[]);
    friend void operator<<(Matrix &a, int y[]);
};
 
void operator>>(Matrix a, int x[]) {
    x[0= a.a1;
    x[1= a.a2;
    x[2= a.a3;
    x[3= a.a4;
}
 
void operator<<(Matrix &a, int y[]) {
    a.a1 = y[0];
    a.a2 = y[1];
    a.a3 = y[2];
    a.a4 = y[3];
}
 
int main() {
    Matrix a(4321), b;
    int x[4], y[4= { 1,2,3,4 };
    a >> x;
    b << y;
 
    for (int i = 0; i < 4; i++cout << x[i] << ' ';
    cout << '\n';
    b.show();
}
cs


+ Recent posts