exam6.cpp
来自「C++语言程序设计题典」· C++ 代码 · 共 34 行
CPP
34 行
#include <iostream.h>
#include <iomanip.h>
const int M=3;
const int N=4;
class Array
{
int A[M][N];
public:
Array(int a[M][N])
{
for (int i=0;i<M;i++)
for (int j=0;j<N;j++)
A[i][j]=a[i][j];
}
friend ostream & operator << (ostream &out,Array &a);
};
ostream & operator << (ostream &out,Array &a)
{
cout << "输出结果:" << endl;
for (int i=0;i<M;i++)
{
for (int j=0;j<N;j++)
cout << setw(3) << a.A[i][j];
cout << endl;
}
return out;
}
void main()
{
int a[M][N]={{1,3,5,9},{11,13,15,17},{19,21,23,25}};
Array A(a);
cout << A; //调用重载运算符函数
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?