Advertisement
tienanh1999

Untitled

Aug 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include "LivingCreature.h"
  5. using namespace std;
  6.  
  7. struct data
  8. {
  9.     int row;
  10.     int column;
  11.     float **p;
  12. };
  13.  
  14.  
  15. void problem1()
  16. {
  17.    
  18.     data a ,b ,c;
  19.     cout <<"Input row, column: ";
  20.     cin >> a.row >>a.column;
  21.    
  22.     cout <<"Input row, column: ";
  23.     cin >> b.row >>b.column;
  24.     a.p  = new float*[a.row];
  25.     for(int i = 0; i < a.row; ++i)
  26.         a.p[i] = new float[a.column];
  27.    
  28.     b.p  = new float*[a.column];
  29.     for(int i = 0; i < a.column; ++i)
  30.         b.p[i] = new float[a.row];
  31.    
  32.     c.p  = new float*[a.row];
  33.     for(int i = 0; i < a.row; ++i)
  34.         c.p[i] = new float[b.column];
  35.    
  36.     // -------------allocate-----------
  37.     for(int i=0; i<a.row; i++)
  38.         for(int j=0; j<a.column; j++)
  39.             cin >> a.p[i][j];
  40.     // -------------release-----------
  41.     for(int i=0; i<a.row; i++)
  42.     {
  43.         for(int j=0; j<a.column; j++)
  44.         {
  45.             cout <<a.p[i][j] <<" ";
  46.         }
  47.         cout <<endl;
  48.     }
  49.    
  50.     cin.ignore(32767, '\n');
  51.    
  52.     for(int i=0; i<a.column; i++)
  53.         for(int j=0; j<a.row; j++)
  54.             cin >> b.p[i][j];
  55.    
  56.     for(int i=0; i<a.column; i++)
  57.     {
  58.         for(int j=0; j<a.row; j++)
  59.         {
  60.             cout <<b.p[i][j] <<" ";
  61.         }
  62.         cout <<endl;
  63.     }
  64.    
  65.     c.p  = new float*[a.row];
  66.     for(int i = 0; i < a.row; ++i)
  67.         c.p[i] = new float[b.column];
  68.    
  69.     for(int i = 0; i < a.row; ++i)
  70.         for(int j = 0; j < b.column; ++j)
  71.             for(int k = 0; k < a.column; ++k)
  72.             {
  73.                 c.p[i][j] += a.p[i][k] * b.p[k][j];
  74.             }
  75.    
  76.     for(int i=0; i<a.row; i++)
  77.     {
  78.         for(int j=0; j<b.column; j++)
  79.         {
  80.             cout <<c.p[i][j] <<" ";
  81.         }
  82.         cout <<endl;
  83.     }
  84. }
  85.  
  86. int main()
  87. {
  88.     int problem;
  89.     cout <<"Problem: ";
  90.     cin >>problem;
  91.     switch (problem)
  92.     {
  93.         case 1:
  94.             {
  95.                 problem1();
  96.                 break;
  97.             }
  98.            
  99.            
  100.        
  101.     }
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement