64,650
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
using namespace std;
#define row 2
#define col 3
class Rect//矩阵类
{
private:
int m[row][col];//这个数组怎么构造
public:
Rect()
{
}
void input()
{ int a=0,b=0;
for(a=0;a <row;a++)
for(b=0;b <col;b++)
{
cout <<"please input number";
cin>>m[a][b];
}
}
void show()
{ int a=0,b=0;
for(a=0;a <row;a++)
for(b=0;b <col;b++)
cout <<m[a][b];
}
};
void main()
{
Rect A;
A.input();
A.show();
}
#include <iostream>
using namespace std;
class Matrix
{
private:
static const int i = 2;
static const int j = 3;
int array[i][j];
public:
void fill()
{
cout<<"Please fulfill matrix:"<<endl;
for(int row = 0; row < i; row++)
for(int col = 0; col < j; col++)
{
cout<<"Please input array["<<row<<"]["<<col<<"]:\n";
cin>>array[row][col];
}
}
void display()
{
cout<<"Display matrix:"<<endl;
for(int row = 0; row < i; row++)
for(int col = 0; col < j; col++)
cout<<array[row][col]<<(col == j - 1 ? "\n" : "\t");
}
};
int main()
{
Matrix m;
m.fill();
m.display();
}