Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Matrics1{
- public:
- int n;
- int **arr;
- Matrics1(int k);
- };
- class Matrics2{
- public:
- int n;
- int **arr;
- Matrics2(int k);
- };
- Matrics1::Matrics1(int k){
- n = k;
- for(int i = 0; i < k; i++){
- for(int j = 0; j < k; j++){
- arr[i][j] = 1;
- }
- }
- };
- Matrics2::Matrics2(int k){
- n = k;
- for(int i = 0; i < k; i++){
- for(int j = 0; j < k; j++){
- arr[i][j] = 1;
- }
- }
- };
- template<typename T>
- void memAlloc(T &m) {
- m.arr = new int *[m.n];
- for (int i = 0; i < m.n; i++) {
- m.arr[i] = new int[m.n];
- }
- }
- template<typename T>
- void memDel(T &m) {
- for (int i = 0; i < m.n; i++) {
- delete[] m.arr[i];
- }
- delete[] m.arr;
- }
- int main() {
- Matrics1 m(5);
- memAlloc(m);
- Matrics2 b(5);
- memAlloc(b);
- memDel(m);
- memDel(b);
- //суммирование матриц
- for(int i = 0; i < m.n; i++){
- for(int j = 0; j < m.n; j++){
- m.arr[i][j] += b.arr[i][j];
- cout << m.arr[i][j] << ' ';
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement