Infernale

NCTU LAB 24/10 NUM 3 [main.cpp]

Oct 24th, 2019
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include "Matrix.h"
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main(){
  7.   int r1, c1, r2, c2;
  8.   double num;
  9.   while(cin >> r1 >> c1){
  10.     vector <double> coef1, coef2;
  11.     for(int i=0; i<r1*c1; i++){
  12.       cin >> num;
  13.       coef1.push_back(num);
  14.     }
  15.     Matrix m1(r1, c1, coef1);
  16.     cin >> r2 >> c2;
  17.     for(int i=0; i<r2*c2; i++){
  18.       cin >> num;
  19.       coef2.push_back(num);
  20.     }
  21.     Matrix m2(r2, c2, coef2);
  22.     if(m1.isAddable(m2)){
  23.       Matrix res = m1+m2;
  24.       cout << "m1 + m2=" << endl;
  25.       res();
  26.     }else{
  27.       cout << "m1 and m2 are not addable." << endl;
  28.     }
  29.     if(m1.isSubstractable(m2)){
  30.       Matrix res = m1-m2;
  31.       cout << "m1 - m2=" << endl;
  32.       res();
  33.     }else{
  34.       cout << "m1 and m2 are not substractable." << endl;
  35.     }
  36.     if(m1.isMultipliable(m2)){
  37.       Matrix res = m1*m2;
  38.       cout << "m1 * m2=" << endl;
  39.       res();
  40.     }else{
  41.       cout << "m1 and m2 are not multipliable." << endl;
  42.     }
  43.   }
  44.   return 0;
  45. }
Add Comment
Please, Sign In to add comment