Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class CounterType
- {
- public:
- CounterType();
- void setCount(int );
- void upCount();
- void downCount();
- int getCount();
- void printCount();
- private:
- int count;
- };
- int main(){
- CounterType counter;
- int i;
- for(i=0;i<10;i++)
- {counter.upCount();
- counter.printCount();
- }
- for(i=0;i<5;i++)
- {counter.downCount();
- counter.printCount();
- }
- system("pause");
- return 0;
- }
- CounterType::CounterType(){
- count=0;
- }
- void CounterType::setCount(int c){
- if(c>=0)
- count=c;
- else
- {count=0;
- cout<<"Invalid count initialization,\n will set to 0\n";
- }
- }
- void CounterType::upCount(){
- count++;
- }
- void CounterType::downCount(){
- if(count>0)
- count--;
- else
- cout<<"This will set count < 0\nothing is being done\n";
- }
- int CounterType::getCount(){
- return count;
- }
- void CounterType::printCount(){
- cout<<"count="<<count<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement