编写一个简易计算器的源代码

上传人:飞*** 文档编号:6405266 上传时间:2017-09-11 格式:DOC 页数:12 大小:66KB
返回 下载 相关 举报
编写一个简易计算器的源代码_第1页
第1页 / 共12页
编写一个简易计算器的源代码_第2页
第2页 / 共12页
编写一个简易计算器的源代码_第3页
第3页 / 共12页
编写一个简易计算器的源代码_第4页
第4页 / 共12页
编写一个简易计算器的源代码_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《编写一个简易计算器的源代码》由会员分享,可在线阅读,更多相关《编写一个简易计算器的源代码(12页珍藏版)》请在金锄头文库上搜索。

1、AStack.h#ifndef ASTACK_HEADER#define ASTACK_HEADER#include using namespace std;template class AStackprivate:int size;int top;Elem* listArray;public:AStack() size = 100; top = 0; listArray = new Elem100; AStack() delete listArray; void clear() top = 0; bool push(Elem& item)if (top = size) return fals

2、e;else listArraytop+ = item; return true; bool pop(Elem& it)if (top = 0) return false;else it = listArray-top; return true; bool topValue(Elem& it) constif (top = 0) return false;else it = listArraytop - 1; return true; int length() const return top; ;#endifFunction.cpp#include function.h#include AS

3、tack.h#include #include void calUserInfo()cout= 48) & (int)ch #include #include using namespace std;int main()char str100 = 0;AStack opnd; /用于存放数据AStack optr; /用于存放操作符char now_ch = =; /用于记录当前字符char prior_ch = 0; /用于记录前一个字符double now_dig = 0; /用于记录当前一个数字double prior_dig = 0; /用于记录前一个数字double value =

4、0; /用于存放计算后的值bool point = false; /用于判断是否有小数点int point_num = 1; /用于记录数字后面的小数点位数char topValue; /用于记录 opnd 的 top 上的值char option = Y; /用于判断是否要继续运算doprior_dig = 0; /在 opnd 中提前放一个 0now_ch = =;opnd.push(prior_dig);optr.push(now_ch);system(cls);calUserInfo();cout str;bool exitPoint = false;/*对每个字符的处理*/for(i

5、nt i = 0; i osp(now_ch)if(now_ch = ) & topValue = ()break;dodouble x = 1,y = 0;opnd.pop(x);opnd.pop(y);if( cal(topValue,y,x,value) )opnd.push(value);if(!optr.pop(topValue)break;while(isp(topValue) osp(now_ch);/ if(topValue != ()if (now_ch != )optr.push(topValue);optr.push(now_ch);prior_ch = now_ch;/*其他情况报错*/elsebreak;/*其他情况报错*/elsecout option;/*清空数字栈和操作符栈*/opnd.clear();optr.clear();while(option = Y);return 0;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 研究报告 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号