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

来源:互联网 发布:老薛主机 知乎 编辑:程序博客网 时间:2024/05/17 08:10

头文件名:hanshu.h


#include"iostream"using namespace std;class Calculator{private:double count;public:Calculator(double a):count(a){};double getcount(){return count;}void  operator++(int){count++;cout << count << endl ;}void  operator++(){++count;cout << count << endl ;}void  operator--(int){count--;cout << count << endl ;}void  operator--(){--count;cout << count << endl;}void  operator+(Calculator b){cout << this->count+b.count << endl ;}void operator-(Calculator b){cout << this->count-b.count << endl ;}};

主函数


#include"iostream"#include"hanshu.h"using namespace std;void main(){Calculator a(6335546546),b(20.1);if((a.getcount()>=0)&&(a.getcount()<=65535)){a++;++a;a--;--a;if((b.getcount()>=0)&&(b.getcount()<=65535)){a+b;a-b;}}}


原创粉丝点击