C++ 重载+运算符重载加号 实现矩阵相加
学习C++ 基础知识,这里实现简单的实例,记录下自己学习生活,很简单,大家一起看看吧!
实例代码:
代码如下 | 复制代码 |
#include #include usingnamespacestd; classComplex { private: inti,j,n,a[2][3]; public: Complex(); Complex operator+(Complex &c); voiddisplay(); voidinput(); } t1;
Complex::Complex() { for(inti=0;i<2;i++) for(intj=0;j<3;j++) a[i][j]=0; }
voidComplex::input() { for(i=0;i<2;i++) for(j=0;j<3;j++) cin>>a[i][j]; } voidComplex::display() { n=1; for(i=0;i<2;i++) for(j=0;j<3;j++) { n++; if(n%2==0) cout< cout< } cout< } Complex Complex::operator+(Complex &c) { for(inti=0;i<2;i++) for(intj=0;j<3;j++) t1.a[i][j]=a[i][j]+c.a[i][j]; returnt1; } intmain() { Complex t2,t3,t4; cout<<"请输入2*3个整数"< t2.input(); cout< cout<<"请输入2*3个整数"< t3.input(); cout< cout<<"t2"; t2.display(); cout<<"t3"; t3.display(); t4=t2+t3; cout<<"t4=t2+t3="; t4.display(); return0; } |
恋爱进行时九游版
恋爱进行时九游版是一款以模拟恋爱玩法为核心的角色扮演手游,精
皇室对决fr(Null’s Royale)
皇室对决fr,即皇室战争的私服变态版本,在该版本中玩家能够拥
养了个猫联机版游戏
养了个猫小游戏一个猫咪主题的模拟经营类型的手游,在游戏中我那
模拟山羊收获日小米版
模拟山羊收获日小米版是一个极其魔性的手机游戏,在游戏中玩家将
女配逆袭之素衣
女配逆袭之素衣是一款恋爱养成冒险的一款游戏,可以角色扮演,在