标签:des style blog http color io os ar for
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1273
2 3 4 3 5 3 4 3 1 5 4 3
6 6 5 8 9 6
#include <iostream> using namespace std; class jz { public: friend jz operator +(jz &c1,jz &c2); void display(); void set() { for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { cin>>a[i][j]; } } } private: int a[2][3]; }; jz operator+(jz &c1,jz &c2) { jz c4; for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { c4.a[i][j]=c1.a[i][j]+c2.a[i][j]; } } return jz(c4); } void jz::display() { for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { if(j==0) cout<<a[i][j]; else cout<<" "<<a[i][j]; } cout<<endl; } } int main() { jz c1,c2,c3; c1.set(); c2.set(); c3=c1+c2; c3.display(); return 0; }
面向对象程序设计上机练习十一(运算符重载)(SDUTOJ1273)
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/zhangmingcheng/p/4044323.html