|
发表于 2009-11-4 01:14:17
|
显示全部楼层
IP:江苏扬州
// test.cpp : Defines the entry point for the console application.
//最后经过同学帮忙
//改成这样就能运行了。 除了上边各位帮忙指出的问题。还有负值的问题。谢谢各位的帮忙
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "iostream.h"
class matrix
{
private:
int (*x)[3];
int (*y)[3];
public:
matrix(int (*xx)[3],int (*yy)[3])
{
x=xx;
y=yy;
}
~matrix(){};
// void set(int xx[3][3],int yy[3][3]);
void sum();
};
/*
void matrix::set(int xx[3][3],int yy[3][3])
{
x[3][3]=xx[3][3];
y[3][3]=yy[3][3];
}
*/
void matrix::sum()
{
int i,j;
int c[3][3];
int t=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=(*(*(x+i)+j)+*(*(y+i)+j));
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<c[i][j]<<endl;
}
}
}
void main()
{
int i,j;
int m[3][3];
int n[3][3];
cout<<"please enter the first matrix number\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>m[i][j];
}
cout<<"\nplease enter the second matrix number\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>n[i][j];
}
matrix add(m,n);
// add.set(m,n);
add.sum();
} |
|