-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpa_lab_7_2_5_(1)-B.cpp
69 lines (65 loc) · 1.73 KB
/
cpa_lab_7_2_5_(1)-B.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
69
#include <iostream>
#include <vector>
using namespace std;
class Matric {
private:
vector <vector<int>> mat;
const int dimy = 0;
const int dimx = 0;
public:
Matric(int const y = 1, int x = 1) :dimx(x), dimy(y) {
for (int i = 0; i < y; i++) {
mat.insert(mat.end(), vector <int>(x));
for (int j = 0; j < x; ++j)
mat[i][j] = 0;
}
}
void AddElem(int q) {
if (q == NULL)
throw string("value is empty");
for (int i = 0; i < dimy; i++)
{
for (int j = 0; j < dimx; j++) {
mat[i][j] += q;
}
}
}
Matric AddMatrics(Matric c) {
if (c.dimx != dimx||c.dimy != dimy)
throw string("Matrices don't fit.\n");
Matric n(dimy, dimy);
for (size_t i = 0; i < dimy; i++)
{
for (size_t j = 0; j < dimx; j++) {
n.mat[i][j] = this->mat[i][j] + c.mat[i][j];
}
}
return n;
}
void print() {
for (size_t i = 0; i < this->dimy; i++)
{
for (size_t j = 0; j < this->dimx; j++) {
cout << this->mat[i][j] << " ";
}
cout << endl;
}
}
};
int main()
{
int x, y;
cin >> x >> y;
Matric a(y, x);
cin >> x >> y;
Matric b(y, x);
cin >> x >> y;
Matric c(y, x);
try { a.AddMatrics(b).print(); }
catch (string e) { cout << e; }
try { a.AddMatrics(c).print(); }
catch (string e) { cout << e; }
try { b.AddMatrics(c).print(); }
catch (string e) { cout << e; }
return 0;
}