Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include "LivingCreature.h"
- using namespace std;
- struct data
- {
- int row;
- int column;
- float **p;
- };
- void problem1()
- {
- data a ,b ,c;
- cout <<"Input row, column: ";
- cin >> a.row >>a.column;
- cout <<"Input row, column: ";
- cin >> b.row >>b.column;
- a.p = new float*[a.row];
- for(int i = 0; i < a.row; ++i)
- a.p[i] = new float[a.column];
- b.p = new float*[a.column];
- for(int i = 0; i < a.column; ++i)
- b.p[i] = new float[a.row];
- c.p = new float*[a.row];
- for(int i = 0; i < a.row; ++i)
- c.p[i] = new float[b.column];
- // -------------allocate-----------
- for(int i=0; i<a.row; i++)
- for(int j=0; j<a.column; j++)
- cin >> a.p[i][j];
- // -------------release-----------
- for(int i=0; i<a.row; i++)
- {
- for(int j=0; j<a.column; j++)
- {
- cout <<a.p[i][j] <<" ";
- }
- cout <<endl;
- }
- cin.ignore(32767, '\n');
- for(int i=0; i<a.column; i++)
- for(int j=0; j<a.row; j++)
- cin >> b.p[i][j];
- for(int i=0; i<a.column; i++)
- {
- for(int j=0; j<a.row; j++)
- {
- cout <<b.p[i][j] <<" ";
- }
- cout <<endl;
- }
- c.p = new float*[a.row];
- for(int i = 0; i < a.row; ++i)
- c.p[i] = new float[b.column];
- for(int i = 0; i < a.row; ++i)
- for(int j = 0; j < b.column; ++j)
- for(int k = 0; k < a.column; ++k)
- {
- c.p[i][j] += a.p[i][k] * b.p[k][j];
- }
- for(int i=0; i<a.row; i++)
- {
- for(int j=0; j<b.column; j++)
- {
- cout <<c.p[i][j] <<" ";
- }
- cout <<endl;
- }
- }
- int main()
- {
- int problem;
- cout <<"Problem: ";
- cin >>problem;
- switch (problem)
- {
- case 1:
- {
- problem1();
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement