标签:des blog io os for 数据 sp div log
2 3 4 3 5 3 4 3 1 5 4 3
6 6 5 8 9 6
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class Matrix //矩阵运算
{
private:
int a[3];
int b[3];
public:
void input()
{
int i;
for(i=0; i<3; i++)
cin>>a[i];
for(i=0; i<3; i++)
cin>>b[i];
}
void outp()
{
int j;
for(j=0; j<3; j++)
{
if(j==2)
cout<<a[j]<<endl;
else
cout<<a[j]<<‘ ‘;
}
for(j=0; j<3; j++)
{
if(j==2)
cout<<b[j]<<endl;
else
cout<<b[j]<<‘ ‘;
}
}
friend Matrix operator +(Matrix &c1, Matrix &c2 )
{
Matrix c;
int i, j;
for(i=0; i<3; i++)
{
c.a[i]=c1.a[i]+c2.a[i];
}
for(j=0; j<3; j++)
{
c.b[j]=c1.b[j]+c2.b[j];
}
return c;
}
};
int main()
{
Matrix c1, c2, d;
c1.input();
c2.input();
d=c1+c2;
d.outp();
return 0;
}
标签:des blog io os for 数据 sp div log
原文地址:http://www.cnblogs.com/yspworld/p/4014265.html