设计一个计算器类Calculator,它只有一个计数的成员count。该计算器的有效范围说0~65535,实现计算器的前自增、后自增、前自减、后自减、两个计算器相加减等运算
2013-12-02 23:44
801 查看
#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;
}
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;
}
相关文章推荐
- PHP函数microtime()
- JSP/Servlet,Tomcat,Jstl各版本对比以及如何查看版本
- http://blog.csdn.net/x86android/article/details/16980967
- Android手机rom分区以及sd卡总结
- SQL SERVER排序函数
- macbook air 安装win7系统时,到最后一步要进入win7,需要给PC设置一个用户名,键盘没反应
- 使用MVCJqGrid
- java反射(3):反射机制
- [WPF] Caliburn Micro学习三 Binding
- MyEclipse 关闭鼠标悬停提示
- Jeecg DataGridTag 的子标签们 二
- 微软Bing发布2013年度搜索排行榜
- Jeecg DataGridTag 的子标签们
- 为android-support-v4.jar打包源码
- MDX Cookbook 05 - 条件过滤 FILTER-COUNT 与 SUM-IIF 实现
- MyEclipse 选中右侧编辑的文件时自动展开左侧目录树
- kkkk
- [Codeforces] 148A - Insomnia cure
- Jeecg 的DataGridTag 表格属性
- 存储器基础知识笔记