C++编程出现点问题 求解答!!
有两个矩阵a和b,均为2行3列,编译程序,求两个矩阵之和。重载插入运算符“<<”和提取运算符“>>”,使之能用于该矩阵的输入输出。重载运算符“+”,使之能用于矩阵相加,如c=a+b。 我变得程序下 求和的结果有错!!!#include<iostream>
using namespace std;
class JU{
public:
JU()
{a[0][0]=0;
b[0][0]=0;
c[0][0]=0;
}
int a_set()
{int i,j;
for( i=0;i<2;i++)
{cout<<"a数组输入第"<<i+1<<"行:"<<endl;
for(j=0;j<3;j++)
{cin>>a[i][j];}
}
return 0;
}
int b_set()
{int i,j;
for( i=0;i<2;i++)
{cout<<"b数组输入第"<<i+1<<"行:"<<endl;
for(j=0;j<3;j++)
{cin>>b[i][j];}
}
return 0;
}
friend JU operator+(JU &a1,JU &b1);
friend ostream &operator<<(ostream &out,JU &obj);
friend istream &operator>>(istream &in,JU &obj);
private:
int a[2][3];
int b[2][3];
int c[2][3];
};
ostream &operator<<(ostream &out,JU &obj)
{out<<obj.a_set();
return out;
}
istream &operator>>(istream &in,JU &obj)
{ return in;}
JU operator+(JU &a1,JU &b1)
{JU temp;
int i,j;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{temp.c[i][j]=a1.a[i][j]+b1.b[i][j];
cout<<temp.c[i][j]<<" ";
}
return temp;
}
void main()
{JU ob_a,ob_b,sum;
cout<<ob_a<<endl;
cout<<ob_b<<endl;
sum=ob_a+ob_b;
}