第十六周 阅读程序一(2)
来源:互联网 发布:电钢琴什么牌子好 知乎 编辑:程序博客网 时间:2024/05/18 07:37
问题及代码:
#include <iostream>using namespace std;namespace CounterNameSpace{int upperbound;int lowerbound;class counter{ int count;public: counter(int n) { if (n <= upperbound ) { count = n; } else { count = upperbound; } } void reset(int n) { if (n < upperbound) { count = n; } } int run() { if (count > lowerbound) { return count--; } else return lowerbound; }};}int main(){ CounterNameSpace::upperbound = 100; CounterNameSpace::lowerbound = 0; CounterNameSpace::counter ob1(10);int i; do { i = ob1.run(); cout << i << " "; } while (i > CounterNameSpace::lowerbound); cout << endl; CounterNameSpace::counter ob2(20); do { i = ob2.run(); cout << i << " "; } while (i > CounterNameSpace::lowerbound); cout << endl; ob2.reset(100); do { i = ob2.run(); cout << i << " "; } while (i > CounterNameSpace::lowerbound); cout << endl; return 0;}
运行结果:
学习心得:
要搞清楚函数还有命名空间之间的关系,不然很容易被绕进去。 0 0
- 第十六周 阅读程序一(2)
- 第十六周 程序阅读一(1)
- 第十六周 阅读程序一(3)
- 第十六周阅读程序(2)
- 第十六周阅读程序(2)
- 第十六周 程序阅读(2)
- 第十六周程序阅读(2)
- 第十六周项目 阅读程序(2)
- 第十六周阅读程序(2)
- 第十六周阅读程序4(2)
- 第十六周阅读程序2
- 第十六周--阅读程序2
- 第十六周阅读程序2
- 第十六周项目一 a阅读程序(2)
- 第十六周项目一 b阅读程序(2)
- 第十六周项目一 d阅读程序(2)
- c++第十六周任务阅读程序(一)
- 第十六周项目一----阅读程序
- screen使用问题,重新attach失败:There is no screen to be resumed matching ***
- 关于linux suse 系统配置ssh防火墙ip规则
- PHP中比较两个时间的大小与日期的差值
- [Starling] RenderTexture - 屏幕截图、角色残影功能的实现基础
- 有趣的二叉查找树
- 第十六周 阅读程序一(2)
- 《柔性字符串匹配》读书笔记(2)之--AC算法(多模式串匹配、前缀匹配)
- 编程随记
- PHP高效率写法
- 最速下降法/steepest descent,牛顿法/newton,共轭方向法/conjugate direction,共轭梯度法/conjugate gradient 及其他
- Android多语言支持以及各国语言Values文件夹命名规则
- CSS Font知识整理总结
- Android耳机HOOK接听键KeyEvent.KEYCODE_HEADSETHOOK
- javascript 循环遍历绑定事件问题