当前位置: 代码迷 >> C语言 >> 一个看像完整的程序,为什么错漏百出
  详细解决方案

一个看像完整的程序,为什么错漏百出

热度:138   发布时间:2006-05-14 17:33:00.0
一个看像完整的程序,为什么错漏百出

#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 &lt;iostream.h&gt;
----------------解决方案--------------------------------------------------------
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
return 0;
}
----------------解决方案--------------------------------------------------------
  相关解决方案