第五周阅读程序2:数组操作对象
来源:互联网 发布:宁波网络继续教育 编辑:程序博客网 时间:2024/06/05 23:44
问题及代码:
#include<iostream>using namespace std;class CE{private: int a,b; int getmin() { return (a<b? a:b); }public: int c; void SetValue(int x1,int x2, int x3) { a=x1; b=x2; c=x3; } int GetMin();};int CE::GetMin() //两个比较函数计算出三个数的最小值{ int d=getmin(); return (d<c? d:c);}int main(){ int x=5,y=12,z=8; CE *ep; //指向对象的指针 ep=new CE; //new开辟一个新的存储空间,存放对象 ep->SetValue(x+y,y-z,10); //为存放的对象赋值 (17,4,10) cout<<ep->GetMin()<<endl; //输出三个数中的最小值 4 CE a=*ep; //新建一个对象a 赋值为 ep指向的对象的数据 cout<<a.GetMin()*3+15<<endl;//4*3+15=27 return 0;}
运行结果:
知识点总结:
利用指针操作对象
程序详解如程序注释
0 0
- 第五周阅读程序2:数组操作对象
- 第五周程序阅读(2)
- 第五周 阅读程序 2
- 第五周程序阅读
- 第五周阅读程序
- 第五周 程序阅读
- 第五周阅读程序1:用指针建立对象
- 第五周阅读程序3:对象指针小结
- 第五周程序阅读(2)
- 第五周 阅读程序(2)
- 第五周 阅读程序(2)
- 第五周 阅读程序(2)
- 第五周程序阅读(1)
- 第五周程序阅读(3)
- 第五周程序阅读(4)
- 第五周程序阅读(5)
- 第五周程序阅读(6)
- 第五周阅读程序一
- 通过vnc viewer连接64位ubuntu 14.02 LTS 云主机上
- 第五周项目4-静态成员应用
- hdu 2203 亲和串 KMP入门
- 第五周 课后实践:程序阅读(1)
- 静态成员应用
- 第五周阅读程序2:数组操作对象
- 状态值速查表
- 安装ECC EHP6 on Windows Server 2008
- git stash 学习
- 第五周项目三——用多文件组织多个类的程序
- HDU2393 Higher Math【几何】【水题】
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现 A--A Repeating Characters
- android5.0编译问题:No rule to make target 'external/chromium_org/third_party/angle/.git/index',
- 面试题之_00(旋转字符串)