include iostream include stdio using namespace std class Matrix privat

 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
#include <iostream>
#include <stdio.h>
using namespace std;
class Matrix {
private:
int x;
int y;
int **arr;
public:
Matrix(int x, int y) {
this->x = x;
this->y = y;
}
void setMatrix() {
arr = new int *[x];
for (int i = 0; i < x; i++) arr[i] = new int [y];
for (int i = 0; i < this->x; i++) {
for (int j = 0; j < this->y; j++) {
cout << "arr[" << i << "][" << j << "] = ";
cin >> arr[i][j];
}
}
}
void getMatrix(int a, int b) {
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
cout << arr[i][j] << " ";
}
cout << "\n";
}
}
void getSumm(int n) {
int summ = 0;
for (int j = 0; j < y; j++) {
summ+= arr[n][j];
}
cout << summ << endl;
}
};
int main() {
setlocale(LC_ALL, "rus");
Matrix arr(3, 3);
arr.setMatrix();
arr.getMatrix(2, 2);
arr.getSumm(2);
return 0;
}