第七单元 7.10
2015-06-30 14:11
211 查看
#include<iostream.h> class base { public: base(int a,int b,int c,int d); base(){} friend base operator+(base &x,base &y); friend base operator-(base &x,base &y); void input(); void show(); private: int a[2][2]; }; void base::show() { for(int i=0;i<2;i++) for(int j=0;j<2;j++) cout<<a[i][j]<<endl; } base::base(int i,int b,int c,int d) { int* p=a[0]; *p=i; p++; *p=b; p++; *p=c; p++; *p=d; } void base::input() { cin>>a[0][0]>>a[0][1]>>a[1][0]>>a[1][1]; cout<<endl; } base operator+(base &x,base &y) { base co; for(int i=0;i<2;i++) for(int j=0;j<2;j++) co.a[i][j]=y.a[i][j]+x.a[i][j]; return co; } base operator-(base &x,base &y) { base co; for(int i=0;i<2;i++) for(int j=0;j<2;j++) co.a[i][j]=x.a[i][j]-y.a[i][j]; return co; } int main() { base i(15,6,13,21),j,z; cout<<"please input 4 number:"<<endl; j.input(); z=i+j; cout<<"i+j="<<endl; z.show(); z=i-j; cout<<"i-j="<<endl; z.show(); return 0; }
相关文章推荐
- Linux下安装nginx
- Linux服务器管理: 系统的进程管理终止进程kill命令
- org.tinygroup.cache-缓存接口
- producer怎样发送消息到指定的partitions
- 经验分享:新GRE填空材料的使用及时间
- Application Layer
- awk中RS,ORS,FS,OFS区别与联系
- oracle11g中SQL优化(SQL TUNING)新特性之Adaptive Cursor Sharing (ACS)
- Java 对象复制
- Ubuntu配置Samba
- Delphi的基本函数
- org.tinygroup.templateweblayer-web层扩展
- 在mac上安装xcode时 弹出需要关闭itunes的警告 解决办法
- org.tinygroup.jcscache-JCS缓存解决方案
- 图片储存
- Linux用户态和内核态
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 安装和使用Linux花生壳(公网版)
- Java EE应用的分层模型
- org.tinygroup.ehcache-EhCache缓存解决方案