#include <iostream>
using namespace std;
#include <iomanip>
const int row=2;
const int col=3;
class array{
private:
int m[row][col];
public:
array(){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
m[i][j]=0;
}
}
}
array(int a,int b,int c,int d,int e,int f){
m[0][0]=a;m[0][1]=b;m[0][2]=c;
m[1][0]=d;m[1][1]=e;m[1][2]=f;
}
void getarray(){
cout<<"Please input the data:"<<endl;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cin>>m[i][j];
}
}
}
void show(){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cout<<m[i][j];
}
cout<<"\n";
}
}
array operator +(array &a){
array temp;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
temp.m[i][j]=a.m[i][j]+m[i][j];
}
}
return temp;
}
array operator -(array &a){
array temp;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
temp.m[i][j]=m[i][j]-a.m[i][j];
}
}
return temp;
}
int main(){
array X(1,2,3,4,5,6);
array Y,Z;
Y.getarray();
cout<<"The X:"<<endl;
X.show();
cout<<"The Y:"<<endl;
Y.show();
cout<<"The X+Y:"<<endl;
Z=X+Y;
Z.show();
cout<<"The X-Y:"<<endl;
Z=X-Y;
Z.show();
return 0;
}
class array{少了结束的右括号,在类结束的地方加上。
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632