7.9
来源:互联网 发布:cam编程视频 编辑:程序博客网 时间:2024/06/13 22:54
#include<iostream> #include<iomanip>using namespace std;const int r=2; const int c=3;class A { public: A(); //构造函数 A(int a,int b,int c,int d,int e,int f); void get_A( ); //键盘输入数组的值 void show(); //显示数组的值 A operator+(A &X); //相加 A operator-(A &X); //相减 private: int m[r][c]; }; A::A() { for(int i=0; i<r; i++) for(int j=0;j<c; j++) m[i][j]=0; } A::A(int a,int b,int c,int d,int e,int f) { //由构造函数设置数组的值 m[0][0]=a; m[0][1]=b; m[0][2]=c; m[1][0]=d; m[1][1]=e; m[1][2]=f; } void A::get_A( ) //键盘输入数组的值 { cout<<"Please input 2*3 data:"<<endl; for (int i=0; i<r; i++) for (int j=0;j<c; j++) cin>>m[i][j]; } void A::show() //显示数组 { for (int i=0; i<r;i++) { for (int j=0;j<c;j++ ) cout<<setw(5)<<m[i][j]; cout<<endl; } } A A::operator+(A &X) //相加 { A temp; for (int i=0;i<r; i++) for(int j=0;j<c;j++) temp.m[i][j]=m[i][j]+X.m[i][j]; return temp; } A A::operator-(A &X) //相减 { A temp; for (int i=0; i<r; i++) for (int j=0; j<c; j++ ) temp.m[i][j]=m[i][j]-X.m[i][j]; return temp; } int main(){ A X(6,7,8,9,10,11); A Y,Z; Y.get_A(); cout<<"X:"<<endl; X.show(); cout<<"Y:"<<endl; Y.show(); Z=X+Y; cout<<"X+Y:"<<endl; Z.show(); Z=X-Y; cout<<"X-Y:"<<endl; Z.show(); return 0; }
0 0
- 7.9
- 7.9
- 7.9.2008
- 7.9-4
- 7.9 数组
- 练习7.9
- 7.9作业
- 7.9(lwip)
- cpp 7.9
- python_(7.9)
- 习题7.9
- 7.9.环境变量(Environment Variables)
- Portable Passware Kit 7.9
- 7.9-7.14 PLAN
- 第七章问题7.9
- Eclipseme1.7.9下载
- 工作日志 7.9
- 7.9 单词游戏 搜索
- 欢迎使用CSDN-markdown编辑器
- 【高德地图API】从零开始学高德JS API(八)——地址解析与逆地址解析
- docker的日志
- python中的三个读read(),readline()和readlines()
- spring框架学习之一
- 7.9
- 让Docker功能更强大的10个开源工具
- 欢迎使用CSDN-markdown编辑器
- OC基础知识总结
- ios开发小技巧之 pch文件的添加以及自定义的LOG
- Launch Screen在iOS7/8中的实现
- UFLDL(新版)中文翻译——Supervised Learning and Optimization: Vectorization
- 深入理解 Docker Volume
- 去除listview下拉时候顶部出现的阴影