VC++实现标准型计算器步骤及源码
VC++实现标准型计算器步骤及源码
- int numb;
- int h; //.计数
- double temp4;
- double temp1;
- double temp3;
- double temp2;
- CString ss;
- char sign;
- int a; //减法计数
- int b; //乘法计数
- int c; //除法计数
- int d; //加法计数
- sign=0;
- CString ss="0";
- temp4=0;
- temp2=0;
- a=b=c=d=0;
- h=0;
- numb=0;
- void CShiyanDlg::OnOn1()
- {
- UpdateData(1);//上传数据开启
- if(numb==1)//判断是否已经按下=号建
- {
- ss="";
- m_text;
- numb=0;
- }
- int a;
- a=ss.GetLength();//截取当前显示框字符串长度
- ss.Insert(a,"1");//插入字符
- m_text=ss;
- UpdateData(0);//上传数据关闭
- // TODO: Add your control notification handler code here
- }
“+”号键程序:
- void CShiyanDlg::Onadd()
- {
- h=0;
- a=b=c=0;
- d++;
- UpdateData(1);
- temp1=atof(ss);
- if((sign=='-')||(sign=='*')||(sign=='/'))
- {
- switch(sign)//change
- {
- case'-':
- {
- temp1=atof(ss);
- temp4=temp4-temp1;
- break;
- }
- case'*':
- {
- temp1=atof(ss);
- temp4=temp4*temp1;
- break;
- }
- case'/':
- {
- temp1=atof(ss);
- temp4=temp4/temp1;
- break;
- }
- }
- }
- else
- {
- if (d==1)///carefull!!
- temp4=temp1;
- else
- temp4=temp4+temp1;
- }
- ss="";
- m_text=ss;
- m_show=temp4;
- sign='+';
- //numb++;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
“-”号键程序:
- void CShiyanDlg::Onsub()
- {
- h=0;
- b=c=d=0;
- a++;
- UpdateData(1);
- temp1=atof(ss);
- if((sign=='+')||(sign=='*')||(sign=='/'))
- {
- switch(sign)//change
- {
- case'+':
- {
- temp1=atof(ss);
- temp4=temp4+temp1;
- break;
- }
- case'*':
- {
- temp1=atof(ss);
- temp4=temp4*temp1;
- break;
- }
- case'/':
- {
- temp1=atof(ss);
- temp4=temp4/temp1;
- break;
- }
- }
- }
- else
- {
- if (a==1)///carefull!!
- temp4=temp1;
- else
- temp4=temp4-temp1;
- }
- ss="";
- m_text=ss;
- m_show=temp4;
- sign='-';
- //numb++;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
“*”号键程序:
- void CShiyanDlg::Onmul()
- {
- a=c=d=0;
- h=0;
- b++;
- UpdateData(1);
- temp1=atof(ss);
- if((sign=='+')||(sign=='-')||(sign=='/'))
- {
- switch(sign)//change
- {
- case'+':
- {
- temp1=atof(ss);
- temp4=temp4+temp1;
- break;
- }
- case'-':
- {
- temp1=atof(ss);
- temp4=temp4-temp1;
- break;
- }
- case'/':
- {
- temp1=atof(ss);
- temp4=temp4/temp1;
- break;
- }
- }
- }
- else
- {
- if (b==1)///carefull!!
- temp4=temp1;
- else
- temp4=temp4*temp1;
- }
- ss="";
- m_text=ss;
- m_show=temp4;
- sign='*';
- //numb++;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
“.”键程序:
- void CShiyanDlg::Onpoint()
- {
- UpdateData(1);
- int a;
- if(h==0)
- {
- a=ss.GetLength();
- ss.Insert(a,".");
- m_text=ss;
- }
- else
- {;}
- h=1;
- UpdateData(0);
- //sign=0;
- //a=0;
- // TODO: Add your control notification handler code here
- }
乘方键程序:
- void CShiyanDlg::Onsqrt() //try again
- {
- UpdateData(1);
- temp4=atof(ss)*atof(ss);
- ss.Format(_T("%f"),temp4);
- m_text=ss;
- m_show=temp4;
- //sign=0;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
“+/-”键程序:
- void CShiyanDlg::Onsign()
- {
- UpdateData(1);
- numb=0;
- temp2=-atof(ss);
- ss.Format(_T("%f"),temp2);
- m_text=ss;
- m_show=temp2;
- temp2=0;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
“C”键程序:
- void CShiyanDlg::OnCE() //C
- {
- numb=0;
- h=0;
- UpdateData(1);
- ss="";
- m_text=ss;
- m_show=atof(ss);
- temp1=0;
- temp2=0;
- temp3=0;
- temp4=0;
- sign='o';
- UpdateData(0);
- a=b=c=d=0;
- // TODO: Add your control notification handler code here
- }
“DEL”键程序:
- void CShiyanDlg::Ondel()
- {
- UpdateData(1);
- int u,v;
- ss=m_text;
- v=ss.GetLength();
- u=v-1;
- ss.Format("%s",ss.Left(u));
- m_text=ss;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
“=”号建:
- void CShiyanDlg::Onequ()
- {
- numb=1;
- h=0;
- UpdateData(1);
- switch(sign)
- {
- case '+':
- {
- a=b=c=0;
- temp1=atof(ss);
- d++;
- if (d==1)
- temp4=temp1;
- else
- temp4=temp4+temp1;
- ss.Format(_T("%f"),temp4);
- m_text=ss;
- m_show=temp4;
- temp1=0;
- temp4=0;
- d=0;
- break;
- }
- case '-':
- {
- b=c=d=0;
- temp1=atof(ss);
- a++;
- if (a==1)
- temp4=temp1;
- else
- temp4=temp4-temp1;
- ss.Format(_T("%f"),temp4);
- m_text=ss;
- m_show=temp4;
- temp1=0;
- temp4=0;
- a=0;
- break;
- }
- case '*':
- {
- a=c=d=0;
- temp1=atof(ss);
- b++;
- if (b==1)
- temp4=temp1;
- else
- temp4=temp4*temp1;
- ss.Format(_T("%f"),temp4);
- m_text=ss;
- m_show=temp4;
- temp1=0;
- temp4=0;
- b=0;
- break;
- }
- case '/':
- {
- a=b=d=0;
- temp1=atof(ss);
- c++;
- if (c==1)
- temp4=temp1;
- else
- temp4=temp4/temp1;
- ss.Format(_T("%f"),temp4);
- m_text=ss;
- m_show=temp4;
- temp1=0;
- temp4=0;
- c=0;
- break;
- }
- //a=b=c=d=0;
- }
- sign=0;
- UpdateData(0);
- // TODO: Add your control notification handler code here
- }
VC++实现标准型计算器步骤及源码的更多相关文章
- PHP 使用GD库合成带二维码的海报步骤以及源码实现
PHP 使用GD库合成带二维码的海报步骤以及源码实现 在做微信项目开发过程中,经常会遇到图片合成的问题,比如将用户的二维码合成到宣传海报中,那么,遇到这种情况,利用PHP的GD库也是很容易实现的,实现 ...
- PHP 使用GD库合成带二维码和圆形头像的海报步骤以及源码实现
PHP 使用GD库合成带二维码和圆形头像的海报步骤以及源码实现 之前记录过一篇文章,不过那只是简单将二维码合成到海报中去,这次还要合成头像,而且是圆形.所需要素材就不一一列举,直接代码吧 1.先获取用 ...
- Mybatis源码解析,一步一步从浅入深(二):按步骤解析源码
在文章:Mybatis源码解析,一步一步从浅入深(一):创建准备工程,中我们为了解析mybatis源码创建了一个mybatis的简单工程(源码已上传github,链接在文章末尾),并实现了一个查询功能 ...
- ubuntu安装qt步骤(源码)
1.安装gcc,g++ sudo apt-get install gcc sudo apt-get install g++ 2.解压源码包 tar xvzf qt-xxxx 3.安装xlib库 sud ...
- C语言实现计算器,附源码,超简单!
#include<stdio.h> #include<math.h> void main() { calculator(); } double calculator() { / ...
- 微信小程序实例源码大全
微信小程序实例源码大全下载 微信小应用示例代码(phodal/weapp-quick)源码链接:https://github.com/phodal/weapp-quick 微信小应用地图定位demo( ...
- Android源码之Gallery专题研究(1)
前言 时光飞逝,从事Android系统开发已经两年了,总想写点什么来安慰自己.思考了很久总是无法下笔,觉得没什么好写的.现在终于决定写一些符合大多数人需求的东西,想必使用过Android手机的人们一定 ...
- 近期热门微信小程序demo源码下载汇总
近期微信小程序demo源码下载汇总,乃小程序学习分析必备素材!点击标题即可下载: 即速应用首发!原创!电商商场Demo 优质微信小程序推荐 -秀人美女图 图片下载.滑动翻页 微信小程序 - 新词 GE ...
- jQuery源码研究——怎么看源码
废话 这几天有想看源码的想法,于是就开始了源码的研究,经过几天的摸索发现看源码还是有点技巧在里面的,想着把这些东东写下来作为一个小总结. 在一个多月前我对Vue源码进行了一次研究,那时看源码的方式基本 ...
随机推荐
- requests模块发送数据
通过json dumps发送 import requests import json def agent(): """ 执行命令采集硬件信息 将执行的信息发送给API : ...
- Python与C/C++相互调用(转)
原文链接 作者 一.问题 Python模块和C/C++的动态库间相互调用在实际的应用中会有所涉及,在此作一总结. 二.Python调用C/C++ 1.Python调用C动态链接库 Python调用C库 ...
- ASP.NET IHttpModule IHttpHandler IHttpHandlerFactory 拦截请求
先来看看代码,拦截所有Http请求类.下面包含了两种类的集成 IHttpModule IHttpHandlerFactory using System; using System.Collection ...
- 安全开发Java动态代理
关于安全开发的一些思考 之前面试某宝的时候,某人问过我,如果解决开发不懂安全的问题,就比如说SSRF,XEE这样的漏洞,如果一旦发生,应该如果立刻去响应,并帮助开发人员修复漏洞,难道写一个jar包?然 ...
- Matlab[linux]安装问题
OS : Arch Linux 桌面:Gnome X11 软件是从网上下载的iso文件,对文件挂载或者使用解压软件解压,我个人更喜欢挂载,解压有点麻烦(我比较懒) 软件:matlab(R2016) 开 ...
- 01.CNN调参
转载:调参是个头疼的事情,Yann LeCun.Yoshua Bengio和Geoffrey Hinton这些大牛为什么能够跳出各种牛逼的网络? 下面一些推荐的书和文章:调参资料总结Neural Ne ...
- mysql乐观锁总结和实践(转载)
原文地址:http://chenzhou123520.iteye.com/blog/1863407 乐观锁介绍: 乐观锁( Optimistic Locking ) 相对悲观锁而言,乐观锁假设认为数据 ...
- docker修改数据库密码
运行mysql(--name 容器名称 -e MYSQL_ROOT_PASSWORD设置初始密码 -p 3307:3306 端口映射,主机端口3307) docker run --name my ...
- CSS效果篇--纯CSS+HTML实现checkbox的思路与实例
checkbox应该是一个比较常用的html功能了,不过浏览器自带的checkbox往往样式不怎么好看,而且不同浏览器效果也不一样.出于美化和统一视觉效果的需求,checkbox的自定义就被提出来了. ...
- formData+ajax文件上传
html代码: <form class="form-horizontal" enctype="multipart/form-data" method=&q ...