设计一个计算器类Calculator,它只有一个计数的成员count。该计算器的有效范围说0~65535,实现计算器的前自增、后自增、前自减、后自减、两个计算器相加减等运算

来源:互联网 发布:端口范围 编辑:程序博客网 时间:2024/06/07 05:12
#include<iostream>
using std::cout;
using std::endl; 
class Calculator{  
private:  
    double count;  
public:  
    Calculator(double a):count(a){};  
    double getcount(){  
        return count;  
    }  
    void  operator++(int){  
        count++;  
        cout << "count:"<<count << endl ;  
    }  
    void  operator++(){  
        ++count;  
        cout <<"count:"<<count << endl ;  
    }  
    void  operator--(int){  
        count--;  
        cout <<"count:"<<count << endl ;  
    }  
    void  operator--(){  
        --count;  
        cout << "count"<< endl;  
    }  
   void  operator+(Calculator b){
        cout <<"conut:"<<this->count+b.count << endl ;  
    }  
   void operator-(Calculator b){  
      cout <<"count:"<<this->count-b.count << endl ;  
    }  
};     
void main()  
{  
    Calculator a(5),b(6);  
    if((a.getcount()>=0)&&(a.getcount()<=65535))  
        a++;  
        ++a;  
        a--;  
        --a;
        if((b.getcount()>=0)&&(b.getcount()<=65535))  
        a+b;  
        a-b; 
          
原创粉丝点击