Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "cmake-build-debug/declaration.h"
- using namespace std ;
- int main() {
- Matrix a(3, 4);
- Matrix b(2,2);
- b.addElem(1,0,0);
- b.addElem(2,1,0);
- a.addElem(1,0,0);
- a.addElem(2,0,1);
- a.addElem(9,1,0);
- a.addElem(10,1,1);
- for (int i=0;i<3;i++)
- {
- for (int j=0;j<4;j++)
- {
- if (a.isEx(i,j))
- {
- cout << a.getElem(i,j)*(-1)<< " ";
- } else cout << "Null ";
- }
- cout <<endl;
- }
- cout<<endl;
- a.Check(a,100);
- cout<<endl;
- for (int i=0;i<a.getN();i++)
- {
- for (int j=0;j<a.getM();j++)
- {
- if (a.isEx(i,j))
- {
- cout << a.getElem(i,j)*(-1)<< " ";
- } else cout << "Null ";
- }
- cout <<endl;
- }
- cout<<endl;
- a=b;
- for (int i=0;i<a.getN();i++)
- {
- for (int j=0;j<a.getM();j++)
- {
- if (a.isEx(i,j))
- {
- cout << a.getElem(i,j)*(-1)<< " ";
- } else cout << "Null ";
- }
- cout <<endl;
- }
- cout<<endl;
- a.sum(10,0,1);
- for (int i=0;i<a.getN();i++)
- {
- for (int j=0;j<a.getM();j++)
- {
- if (a.isEx(i,j))
- {
- cout << a.getElem(i,j)*(-1)<< " ";
- } else cout << "Null ";
- }
- cout <<endl;
- }
- return 0;
- }
- // main
- //
- // Created by brfh on 21.04.18.
- //
- #include <iostream>
- using namespace std ;
- #include <algorithm>
- #include "declaration.h"
- Matrix:: Matrix(int n,int m)
- {
- this->n=n;
- this->m=m;
- arr = new Point*[n];
- for (int j=0;j<n;j++)
- {
- arr[j]=new Point[m];
- }
- }
- void Matrix::addElem(int a,int i,int j)
- {
- this->arr[i][j].v=a;
- this->arr[i][j].ex= true;
- }
- int& Matrix::getElem(int i,int j)
- {
- return (this->arr[i][j].v);
- }
- bool Matrix::isEx(int i,int j)
- {
- return this->arr[i][j].ex;
- }
- Matrix::Matrix(const Matrix &obj)
- {
- arr = new Point*[obj.n];
- for (int i =0;i<obj.n;i++)
- {
- arr[i]=new Point[obj.m];
- }
- this->n=obj.n;
- this->m=obj.m;
- for (int i =0;i<obj.n;i++)
- {
- std::copy(obj.arr[i],obj.arr[i]+obj.n,arr[i]);
- }
- }
- int Matrix::getN()
- {
- return this->n;
- }
- int Matrix::getM()
- {
- return this->m;
- }
- Matrix::~Matrix()
- {
- delete arr;
- }
- int& Matrix::operator[](int index) {}
- void Matrix::sum(int x, int i, int j)
- {
- for (int k=0;k<this->m;k++)
- {
- this->arr[j][k].v+=this->arr[i][k].v*x;
- }
- }
- void Matrix::Check(Matrix a,int x)
- {
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<m;j++)
- {
- a.addElem(a.arr[i][j].v*x,i,j);
- cout<<a.getElem(i,j) << " " ;
- }
- cout<<endl;
- }
- cout<<endl;
- }
- Matrix& Matrix::operator=(const Matrix &obj)
- {
- if (this != &obj)
- {
- Point **a=new Point*[obj.n];
- for (int i=0;i<obj.n;i++)
- {
- a[i]=new Point[obj.m];
- }
- for (int i=0; i<obj.n;i++)
- {
- std::copy(obj.arr[i],obj.arr[i]+obj.n,a[i]);
- }
- for (int i=0; i<n; delete arr[i++]);
- delete arr;
- n=obj.n;
- m=obj.m;
- arr=a;
- }
- return *this;
- }
- Point::Point()
- {
- this->ex= false;
- this->v=0;
- }
- //
- //
- // Created by brfh on 21.04.18.
- //
- #ifndef LAB1_DECLARATION_H
- #define LAB1_DECLARATION_H
- #endif //LAB1_DECLARATION_H
- class Point
- {
- public:
- int v;
- bool ex;
- Point();
- };
- class Matrix
- {
- private:
- int n, m;
- Point** arr;
- public:
- Matrix&operator=(const Matrix &obj);
- int getM();
- int getN();
- void cop(Matrix a);
- void Check(Matrix a,int x);
- int& operator [] (int index);
- bool isEx(int i,int j);
- int& getElem(int i, int j);
- void addElem(int a,int i,int j);
- void sum(int x,int i, int j);
- Matrix(int n,int m);
- Matrix(const Matrix &obj);
- virtual ~Matrix();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement