Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include "[lab5]Header.h"
- void Exception::display() {
- std::cout << "Exception! - #" << code_ << ", " << cause_ << '\n';
- }
- Exception::Exception(int code, char* cause) {
- this->cause_ = cause;
- this->code_ = code;
- }
- template <class own>
- own& matrix<own>:: operator()(const int i, const int j) {
- try
- {
- if (i >= n_ || j >= m_) {
- throw Exception(111, (char*)"Out of the range!");
- }
- return point_[m_ * i + j];
- }
- catch (Exception& ex)
- {
- ex.display();
- }
- }
- template<class own>
- matrix<own>::matrix()
- {
- this->n_ = 0;
- this->m_ = 0;
- this->point_ = nullptr;
- }
- template<class own>
- matrix<own>::matrix(int n, int m)
- {
- this->n_ = n;
- this->m_ = m;
- point_ = new own[getSize()];
- for (int i = 0; i < this->getSize(); i++) {
- this->point_[i] = i;
- }
- }
- template<class own>
- matrix<own>::matrix(matrix& other) {
- try
- {
- if (this->getSize() != other.getSize()) {
- throw std::exception("MatriŃes are not equals");
- }
- this->n_ = other.n_;
- this->m_ = other.m_;
- delete point_;
- point_ = new own[getSize()];
- for (int i = 0; i < other.getSize(); i++) {
- this->point_[i] = other.point_[i];
- }
- }
- catch (const std::exception& ex)
- {
- std::cout << ex.what();
- }
- }
- template<class own>
- matrix<own>::~matrix()
- {
- delete[]point_;
- }
- template<class own>
- int matrix<own>::getSize() {
- return n_ * m_;
- }
- template<class own>
- void matrix<own>::printMtr()
- {
- for (int i = 0; i < getSize(); i++) {
- std::cout << point_[i] << ' ';
- }
- }
- template<class own>
- std::ostream& operator<< (std::ostream& out, const matrix<char>& mtr) {
- out << "Matrix is:\n";
- int cur = 0;
- for (int i = 0; i < mtr.n_; i++) {
- for (int j = 0; j < mtr.m_; j++) {
- out << mtr.point_[cur++] << ' ';
- }
- out << '\n';
- }
- out << '\n';
- return out;
- }
- template<class own>
- std::istream& operator>>(std::istream& in, matrix<char>& mtr) {
- for (int i = 0; i < mtr.getSize(); i++) {
- in >> mtr.point_[i];
- }
- return in;
- }
- template<typename T1>
- void swapT1toT2(T1& a, T1& b) {
- T1 temp = b;
- b = a;
- a = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement