#include <iostream.h>
#include <cstdlib>
#include <iomanip.h>
// Array size
const int row = 4;
const int col = 4;
// function prototypes
void time(int firstmatrix[row][col], int secondmatrix[row][col], int timematrix[row][col]);
void matrix(int firstmatrix[row][col],int secondmatrix[row][col]);
void Display(int firstmatrix[row][col], int secondmatrix[row][col], int timematrix[row][col]);
void printrow(int matrix[row][col], int ROW);
void PrintHeader();
void main()
{
// Define matrices
int firstmatrix[row][col];
int secondmatrix[row][col];
int timematrix[row][col];
const int row=4;
const int col=4;
char again = 'n';
int i,j,temp;
cout<<"Please input int matrix firstmatrix[row][col]\n";
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
cin>>temp;
firstmatrix[i][j]=temp;
}
cout<<"Please input int matrix secondmatrix[row][col]\n";
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
cin>>temp;
secondmatrix[i][j]=temp;
}
do
{
system("cls");
time(firstmatrix, secondmatrix, timematrix); // add first and second matrices
Display(firstmatrix, secondmatrix, timematrix); // Display all matrices
cout << "Can't beleive it was so easy? Want to see it again? (y/n) ";
cin >> again;
}
while ((again == 'y') || (again == 'Y'));
return;
}// end main
////////////////////////////////////////////
void timematrix(int firstmatrix[row][col],int secondmatrix[row][col])
{
int i,j,k;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
for(k=0;k<col;k++)
timematrix[i][j]+=firstmatrix[i][k]*secondmatrix[k][j];
}
}
////////////////////////////////////////////
void Display(int firstmatrix[row][col], int secondmatrix[row][col], int timematrix[row][col])
{
// Display the matrices, in row and column format, across the screen
PrintHeader();
for (int r = 0; r < row; ++r)
{
cout << endl;
printrow(firstmatrix, r);
printrow(secondmatrix, r);
printrow(timematrix, r);
}
cout << endl << endl;
return;
}
//////////////////////////////////////////
void printrow(int matrix[row][col], int ROW)
{
// Print one row of each matrix
cout << setw(4) << " ";
for (int c = 0; c < col; ++c)
cout << setw( 4 ) << matrix[row][col];
return;
}
/////////////////////////////////////////
void PrintHeader()
{
// Print header to screen
cout << "CE&SP1\n\nTest program for Group C.\n\n\n";
cout << setw(4) << " " << setw(12) << "FIRST"
<< setw(4) << " " << setw(12) << "SECOND"
<< setw(8) << " " << setw(8) << "ADDITION\n";
return;
}
如何输入firstmatrix和secong matrix?
----------------解决方案--------------------------------------------------------
您好象贴错地方了......
去C++教室那边贴看看吧
----------------解决方案--------------------------------------------------------
#include <iostream.h>
----------------解决方案--------------------------------------------------------
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
return 0;
}
----------------解决方案--------------------------------------------------------