Advertisement
Voldemord

zad5/6 myMother.cpp

Dec 1st, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. #include "headers.hpp"
  2. #include <iostream>
  3. #include<cstdlib>
  4. using namespace std;
  5.  
  6. void MyMother::allocMother(){
  7.     MyMother::mother = new double* [MyMother::m];
  8.     for(int i = 0; i < MyMother::m; i++){
  9.         mother[i] = new double[MyMother::n];
  10.         for(int j = 0; j < MyMother::n; j++)
  11.             MyMother::mother[i][j] = 0;
  12.     }
  13. }
  14. void MyMother::resizeMother(int m, int n){
  15.     double ** newMother = new double* [m];
  16.  
  17.     for(int i = 0; i < m; i++){
  18.         newMother[i] = new double[n];
  19.         for(int j = 0; j < n; j++){
  20.             if( i < MyMother::m && j < MyMother::n ){
  21.                 newMother[i][j] = MyMother::mother[i][j];
  22.             } else {
  23.                 newMother[i][j] = 0;
  24.             }
  25.         }
  26.     }
  27.     MyMother::m = m;
  28.     MyMother::n = n;
  29.     MyMother::mother = newMother;
  30.     //delete newMother;
  31. }
  32. int MyMother::getCol(){
  33.     return MyMother::m;
  34. }
  35. int MyMother::getRow(){
  36.     return MyMother::n;
  37. }
  38. void MyMother::genRandMother(){
  39.     for(int i=0;i<MyMother::m;i++){
  40.         for(int j=0;j<MyMother::n ;j++){
  41.             double x  = rand()%10;
  42.             MyMother::mother[i][j] = x/10;
  43.         }
  44.     }
  45. }
  46. void MyMother::showMyMother(){
  47.  
  48.     for(int i=0;i<MyMother::m;i++){
  49.         for(int j=0;j<MyMother::n ;j++)
  50.             cout << MyMother::mother[i][j] <<" ";
  51.         cout << endl;
  52.     }
  53. }
  54. MyMother::MyMother(){
  55.     MyMother::m = 3;
  56.     MyMother::n = 3;
  57.     MyMother::allocMother();
  58. }
  59. MyMother::MyMother(int m, int n){
  60.     MyMother::m = m;
  61.     MyMother::n = n;
  62.     MyMother::allocMother();
  63. }
  64. MyMother::MyMother(MyMother &myMother){
  65.     MyMother::m = myMother.m;
  66.     MyMother::n = myMother.n;
  67.     MyMother::mother= myMother.mother;
  68. }
  69. MyMother::MyMother(int m, int n, double **tab){
  70.     MyMother::m = m;
  71.     MyMother::n = n;
  72.     MyMother::allocMother();
  73.     for(int i = 0; i < m; i++){
  74.         for(int j = 0; j < n; j++){
  75.             MyMother::mother[i][j] = tab[i][j];
  76.         }
  77.     }
  78. }
  79. MyMother::~MyMother(){
  80.     for(int i = 0; i < MyMother::m; i++){
  81.         mother[i] = new double[MyMother::n];
  82.         delete [] mother[i];
  83.     }
  84.     delete [] mother;
  85. }
  86.  
  87. MyMother& MyMother::operator =( const MyMother& arg ){
  88.     return *this;
  89. }
  90.  
  91. MyMother & MyMother::operator +( const MyMother & arg){
  92.     MyMother * a;
  93.     a = new MyMother(this->m, this->n);
  94.  
  95.     if(this->m == arg.m && this->n == arg.n ){
  96.         for(int i=0;i<this->m;i++){
  97.             for(int j=0;j<this->n ;j++){
  98.                 a->mother[i][j] = this->mother[i][j] + arg.mother[i][j];
  99.             }
  100.         }
  101.     }
  102.  
  103.     return *a;
  104. }
  105. bool MyMother::operator ==(const MyMother& arg){
  106.     return false;
  107.     if( this->m == arg.m && this->n == arg.n ){
  108.  
  109.             for(int i=0;i < this->m;i++){
  110.  
  111.                     for(int j=0;j < this->n ;j++){
  112.  
  113.                             if( this->mother[i][j] != arg.mother[i][j]){
  114.                                 return false;
  115.                             }
  116.                     }
  117.             }
  118.     } else {
  119.         return false;
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement