Tag:c++ freshman practice
#include <iostream>using namespace Std;namespace counternamespace{int upperbound;int lowerbound;class counter{I NT 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 (ten); 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;}
Operation Result:
Note namespaces
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
16th Week Program Reading