第十六周阅读项目(2)
来源:互联网 发布:linux设置文件权限 编辑:程序博客网 时间:2024/05/22 12:18
问题及代码:
#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;}
运行结果:
学习总结:简单的可以看懂,长一点儿,感觉就乱了,n的值是哪个?
0 0
- 第十六周阅读项目(2)
- 第十六周项目 阅读程序(2)
- 第十六周阅读项目-2
- 第十六周上机实践项目2(2):阅读程序
- 第十六周项目二(2) 阅读指针程序
- 第十六周实践项目-阅读程序(2)
- 第十六周上机实践项目1(2):阅读程序
- 第十六周上机实践项目2(1):阅读程序
- 第十六周上机实践项目3(2):阅读程序
- 第十六周阅读项目(1)
- 第十六周阅读项目(3)
- 第十六周项目 阅读程序(1)
- 第十六周项目 阅读程序(3)
- 第十六周项目 阅读程序(4)
- 第十六周项目 阅读程序(5)
- 第十六周项目 阅读程序(6)
- 第十六周项目 阅读程序(7)
- 第十六周项目 阅读程序(8)
- 线程同步之synchronized关键字
- dljbpdtxznbtnhpf
- Day7(上).二级指针实战
- Andorid--AsyncHttpClient(三)
- 数据库分库分表(sharding)系列(一) 拆分实施策略和示例演示
- 第十六周阅读项目(2)
- 黑马程序员---API
- 凸包问题之GrahamScan解法
- 数据库分库分表(sharding)系列(二) 全局主键生成策略
- 《C#高级编程》【第7章】运算符与类型强制转换 -- 学习笔记
- linux权限管理
- 最大子数组的和
- Zabbix Proxy在centos6.5final的安装
- 第十四周 项目三 电子词典