导航:首页 > 编程语言 > vs计算器代码

vs计算器代码

发布时间:2023-05-08 03:22:36

1. 用vs编写一个简单的计算器。 用vs编一个数据结构中的循环结构,选择结构,顺序结构!!!还清还有一

cwa9958 说的有点问题,任何程序,都需要数据结构,只不过有些特别简单而已

编写羡耐计算器,复杂的尘派竖数据结构倒是用不上,关键要掌握下面的几点:
1.正确处理各种输入的顺序及处理和显示(这是计算器代码中最复杂的)
2.灵活应用控件数组
3.正确使用数学函数
4.容错处理技术(这个需要编程人员有很好的调试技巧)

后话:要做到Windows自带的那个的功能,不是一件简单的事,好好编吧,编完后,你会派大发现,你的编程水平会上一个台阶

2. 如何用VS编写一个计算器程序用到C++MFC等。不需要全部代码,数字运算符号各提供一个参考代码即

定义一个全局变量用于存放当前显示的数值。
例如 输猜雹入了11 按一下+号键就写m_Calc=11;//具友兆唤体自己转
再输入加的数值 例如输入了22; 就写m_Calc+=22; 除号键也是 m_Calc=m_Calc/55;
减好凯号键m_Calc-=22;~~

3. 用VS使用C#开发一个简易计算器,实现加减乘除等于基本功能,就和电脑自带的那个差不多,求代码

用数组,打比方,A1。A2
第一输入的数字到A1寄存,第二次的用A2寄存,然后做计算。

4. 在VS2010中编写C#程序计算器

//简单的计算器
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
namespacewincalc
{
///
///SummarydescriptionforcalcForm.
///
publicclasscalcForm:System.Windows.Forms.Form
{
privateSystem.Windows.Forms.Buttonbutton1;
privateSystem.Windows.Forms.Buttonbutton2;
privateSystem.Windows.Forms.Buttonbutton3;
privateSystem.Windows.Forms.Buttonbutton4;
privateSystem.Windows.Forms.Buttonbutton5;
privateSystem.Windows.Forms.Buttonbutton6;
privateSystem.Windows.Forms.Buttonbutton7;
privateSystem.Windows.Forms.Buttonbutton8;
privateSystem.Windows.Forms.Buttonbutton9;
privateSystem.Windows.Forms.Buttonbutton10;
privateSystem.Windows.Forms.ButtonbClr;
privateSystem.Windows.Forms.ButtonbDot;
privateSystem.Windows.Forms.ButtonbPlus;
privateSystem.Windows.Forms.ButtonbSub;
privateSystem.Windows.Forms.ButtonbMul;
privateSystem.Windows.Forms.ButtonbDiv;
privateSystem.Windows.Forms.ButtonbEqu;
privateSystem.Windows.Forms.TextBoxtxtCalc;
//以下是要添加的代码
//定义变量
DoubledblAcc;
DoubledblSec;
boolblnClear,blnFrstOpen;
StringstrOper;
//以上是添加的代码
///
///Requireddesignervariable.
///
privateSystem.ComponentModel.Containercomponents=null;
publiccalcForm()
{
//
//
//
InitializeComponent();
//
//TODO:
//
//以下是要添加的代码
//初始化设量
dblAcc=0;
dblSec=0;
blnFrstOpen=true;
blnClear=true;
strOper=newstring('=',1);
//以上是添加的代码
}
///
///Cleanupanyresourcesbeingused.
///
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#
///
///-donotmodify
///.
///
()
{
this.bPlus=newSystem.Windows.Forms.Button();
this.bMul=newSystem.Windows.Forms.Button();
this.bDot=newSystem.Windows.Forms.Button();
this.txtCalc=newSystem.Windows.Forms.TextBox();
this.bClr=newSystem.Windows.Forms.Button();
this.bDiv=newSystem.Windows.Forms.Button();
this.bSub=newSystem.Windows.Forms.Button();
this.button8=newSystem.Windows.Forms.Button();
this.button9=newSystem.Windows.Forms.Button();
this.bEqu=newSystem.Windows.Forms.Button();
this.button10=newSystem.Windows.Forms.Button();
this.button4=newSystem.Windows.Forms.Button();
this.button5=newSystem.Windows.Forms.Button();
this.button6=newSystem.Windows.Forms.Button();
this.button7=newSystem.Windows.Forms.Button();
this.button1=newSystem.Windows.Forms.Button();
this.button2=newSystem.Windows.Forms.Button();
this.button3=newSystem.Windows.Forms.Button();
this.SuspendLayout();
//
//bPlus
//
this.bPlus.BackColor=System.Drawing.SystemColors.Control;
this.bPlus.ForeColor=System.Drawing.SystemColors.ControlText;
this.bPlus.Location=newSystem.Drawing.Point(208,112);
this.bPlus.Name="bPlus";
this.bPlus.Size=newSystem.Drawing.Size(32,80);
this.bPlus.TabIndex=1;
this.bPlus.Text="+";
//以下是要添加的代码
bPlus.Click+=newSystem.EventHandler(this.btn_Oper);
//以上是添加的代码
//
//bMul
//
this.bMul.Location=newSystem.Drawing.Point(160,112);
this.bMul.Name="bMul";
this.bMul.Size=newSystem.Drawing.Size(32,32);
this.bMul.TabIndex=1;
this.bMul.Text="*";
//以下是要添加的代码
bMul.Click+=newSystem.EventHandler(this.btn_Oper);
//以上是添加的代码
//
//bDot
//
this.bDot.ForeColor=System.Drawing.Color.Black;
this.bDot.Location=newSystem.Drawing.Point(112,208);
this.bDot.Name="bDot";
this.bDot.Size=newSystem.Drawing.Size(32,32);
this.bDot.TabIndex=0;
this.bDot.Text=".";
//以下是要添加的代码
bDot.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//txtCalc
//
this.txtCalc.Location=newSystem.Drawing.Point(16,24);
this.txtCalc.Name="txtCalc";
this.txtCalc.ReadOnly=true;
this.txtCalc.RightToLeft=System.Windows.Forms.RightToLeft.Yes;
this.txtCalc.Size=newSystem.Drawing.Size(224,21);
this.txtCalc.TabIndex=2;
this.txtCalc.Text="";
//
//bClr
//
this.bClr.BackColor=System.Drawing.SystemColors.Control;
this.bClr.ForeColor=System.Drawing.SystemColors.ControlText;
this.bClr.Location=newSystem.Drawing.Point(208,64);
this.bClr.Name="bClr";
this.bClr.Size=newSystem.Drawing.Size(32,32);
this.bClr.TabIndex=0;
this.bClr.Text="AC";
//以下是要添加的代码
bClr.Click+=newSystem.EventHandler(this.btn_clr);
//以上是添加的代码
//
//bDiv
//
this.bDiv.Location=newSystem.Drawing.Point(160,160);
this.bDiv.Name="bDiv";
this.bDiv.Size=newSystem.Drawing.Size(32,32);
this.bDiv.TabIndex=1;
this.bDiv.Text="/";
//以下是要添加的代码
bDiv.Click+=newSystem.EventHandler(this.btn_Oper);
//以上是添加的代码
//
//bSub
//
this.bSub.Location=newSystem.Drawing.Point(160,64);
this.bSub.Name="bSub";
this.bSub.Size=newSystem.Drawing.Size(32,32);
this.bSub.TabIndex=1;
this.bSub.Text="-";
//以下是要添加的代码
bSub.Click+=newSystem.EventHandler(this.btn_Oper);
//以上是添加的代码
//
//button8
//
this.button8.Location=newSystem.Drawing.Point(16,64);
this.button8.Name="button8";
this.button8.Size=newSystem.Drawing.Size(32,32);
this.button8.TabIndex=0;
this.button8.Text="7";
//以下是要添加的代码
button8.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button9
//
this.button9.Location=newSystem.Drawing.Point(64,64);
this.button9.Name="button9";
this.button9.Size=newSystem.Drawing.Size(32,32);
this.button9.TabIndex=0;
this.button9.Text="8";
//以下是要添加的代码
button9.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//bEqu
//
this.bEqu.BackColor=System.Drawing.SystemColors.Control;
this.bEqu.ForeColor=System.Drawing.SystemColors.ControlText;
this.bEqu.Location=newSystem.Drawing.Point(160,208);
this.bEqu.Name="bEqu";
this.bEqu.Size=newSystem.Drawing.Size(80,32);
this.bEqu.TabIndex=1;
this.bEqu.Text="=";
//以下是要添加的代码
bEqu.Click+=newSystem.EventHandler(this.btn_equ);
//以上是添加的代码
//
//button10
//
this.button10.Location=newSystem.Drawing.Point(112,64);
this.button10.Name="button10";
this.button10.Size=newSystem.Drawing.Size(32,32);
this.button10.TabIndex=0;
this.button10.Text="9";
//以下是要添加的代码
button10.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button4
//
this.button4.Location=newSystem.Drawing.Point(112,160);
this.button4.Name="button4";
this.button4.Size=newSystem.Drawing.Size(32,32);
this.button4.TabIndex=0;
this.button4.Text="3";
//以下是要添加的代码
button4.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button5
//
this.button5.Location=newSystem.Drawing.Point(16,112);
this.button5.Name="button5";
this.button5.Size=newSystem.Drawing.Size(32,32);
this.button5.TabIndex=0;
this.button5.Text="4";
//以下是要添加的代码
button5.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button6
//
this.button6.Location=newSystem.Drawing.Point(64,112);
this.button6.Name="button6";
this.button6.Size=newSystem.Drawing.Size(32,32);
this.button6.TabIndex=0;
this.button6.Text="5";
//以下是要添加的代码
button6.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button7
//
this.button7.Location=newSystem.Drawing.Point(112,112);
this.button7.Name="button7";
this.button7.Size=newSystem.Drawing.Size(32,32);
this.button7.TabIndex=0;
this.button7.Text="6";
//以下是要添加的代码
button7.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button1
//
this.button1.BackColor=System.Drawing.SystemColors.Control;
this.button1.ForeColor=System.Drawing.Color.Black;
this.button1.Location=newSystem.Drawing.Point(16,208);
this.button1.Name="button1";
this.button1.Size=newSystem.Drawing.Size(80,32);
this.button1.TabIndex=0;
this.button1.Text="0";
//以下是要添加的代码
button1.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button2
//
this.button2.Location=newSystem.Drawing.Point(16,160);
this.button2.Name="button2";
this.button2.Size=newSystem.Drawing.Size(32,32);
this.button2.TabIndex=0;
this.button2.Text="1";
//以下是要添加的代码
button2.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//button3
//
this.button3.Location=newSystem.Drawing.Point(64,160);
this.button3.Name="button3";
this.button3.Size=newSystem.Drawing.Size(32,32);
this.button3.TabIndex=0;
this.button3.Text="2";
//以下是要添加的代码
button3.Click+=newSystem.EventHandler(this.btn_clk);
//以上是添加的代码
//
//calcForm
//
this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);
this.ClientSize=newSystem.Drawing.Size(256,261);
this.Controls.AddRange(newSystem.Windows.Forms.Control[]{
this.txtCalc,
this.bEqu,
this.bDiv,
this.bMul,
this.bSub,
this.bPlus,
this.bDot,
this.bClr,
this.button10,
this.button9,
this.button8,
this.button7,
this.button6,
this.button5,
this.button4,
this.button3,
this.button2,
this.button1});
this.Name="calcForm";
this.Text="计算器";
this.ResumeLayout(false);
}
#endregion
//以下是要添加的代码
//小数点的操作
privatevoidbtn_clk(objectobj,EventArgsea)
{
if(blnClear)
txtCalc.Text="";
Buttonb3=(Button)obj;
txtCalc.Text+=b3.Text;
if(txtCalc.Text==".")
txtCalc.Text="0.";
dblSec=Convert.ToDouble(txtCalc.Text);
blnClear=false;
}
//程序开始点
privatestaticvoidMain()
{
Application.Run(newcalcForm());
}
privatevoidbtn_Oper(objectobj,EventArgsea)
{
Buttontmp=(Button)obj;
strOper=tmp.Text;
if(blnFrstOpen)
dblAcc=dblSec;
else
calc();
blnFrstOpen=false;
blnClear=true;
}
//等号运算
privatevoidbtn_equ(objectobj,EventArgsea)
{
calc();
}
//所有运算操作
privatevoidcalc()
{
switch(strOper)
{
case"+":
dblAcc+=dblSec;//加号运算
break;
case"-":
dblAcc-=dblSec;//减号运算
break;
case"*":
dblAcc*=dblSec;//乘号运算
break;
case"/":
dblAcc/=dblSec;//除号运算
break;
}
strOper="=";//等号运算
blnFrstOpen=true;
txtCalc.Text=Convert.ToString(dblAcc);//将运算结果转换成字符类型,并输出
dblSec=dblAcc;//将运算数A的值放入运算数B中,以便后面运算
}
//清除按钮
privatevoidbtn_clr(objectobj,EventArgsea)
{
clear();
}
//清除按钮的操作
privatevoidclear()
{
dblAcc=0;
dblSec=0;
blnFrstOpen=true;
txtCalc.Text="";
txtCalc.Focus();//设置焦点为txtCalc
}
//以上是添加的代码
}
}

5. 怎么用vs做一个计算器

首先,点击VS2012,启动VS软件,然后建立如下图所示的应用程序,在图的下面输入项目名

建立基于对话框的标准程序,如下图所示,其余设置采用系统设置,点击完成

如下图,软件会生成下面的对话框,还有相应的库,代码,资源文件

对上面的对话框进行编辑,如下图中所示,最拿闷配后编辑的样子如下,其中1,5,6是Edit 控件,2,7是静态控件,3是buttion,4是取消按钮改了个名字,将各个控件按下图排好,并改好名字,其余部分采用软件默认

对1,5,7控件添加变量,对控件右击,选择如下

如下图变量添加向导,1选择Value,2选择Double (方便计算小数)3,是变量名,我们选择a,相同的方式,对上图中的1,5,7分别添加变量,分别为工a,b,sum

添加完后在对话框上双击计算按钮,就会生成相应的消息映射,进入如下代码中,见下图

在这个函数中添加下面代码,UpdataDate()函数中参数true表示从控件变量中获取数值,false相反
sum=a+b,就是我们先在控件中添加的三个变量,此处所做的计算器只是用来做个加法

添加完上述代码后,编译成功如下所示

ctrl+f5运行如下图

输入数值进行加法计算,你可以进行其它的相关扩展,比如减消指罩羡法,乘法等,都是相同的方法

6. vs2010编译简单计算器窗体

先看看图片 说明以上控件动态生成的,初学可自己拖放控件,以下代码仅供参考 /*设计一个嫌宴歼简单的四则计算器*/ string[]名称={"+","-","*","/"}; Button[]控件组=Array.ConvertAll(名称,控件=>newButton()); EventHandler[]按钮事件=newEventHandler[]{按钮加_Click,按钮减_Click,按钮乘_Click,按钮除_Click}; foreach(Button按钮in控芹冲件组) { 按钮.Text=名称祥孝[--数]; 按钮.Name="按钮"+数.ToString(); 按钮.Parent=this; 按钮.Anchor=(AnchorStyles.Top|AnchorStyles.Left); 按钮.Location=newPoint(100*数,17); 按钮.Click+=按钮事件[数]; } 名称=newstring[]{"值1","值2","结果"}; TextBox[]数字输入框=Array.ConvertAll(名称,控件=>newTextBox()); 数=3; foreach(TextBox输入框in数字输入框) { 输入框.Text=(--数+10).ToString(); 输入框.Name="输入框"+名称[数]; 输入框.Parent=this; 输入框.Anchor=(AnchorStyles.Top|AnchorStyles.Left); 输入框.Location=newPoint(100*数,0); } void按钮加_Click(objectsender,EventArgse) { 四则运算("+"); } void按钮减_Click(objectsender,EventArgse) { 四则运算("-"); } void按钮乘_Click(objectsender,EventArgse) { 四则运算("*"); } void按钮除_Click(objectsender,EventArgse) { 四则运算("/"); } void四则运算(string运算符) { Control.ControlCollection文本框=this.Controls; double值1=int.Parse(文本框[9].Text),值2=int.Parse(文本框[8].Text); switch(运算符) { case"+": {文本框[7].Text=(值1+值2).ToString();} break; case"-": {文本框[7].Text=(值1-值2).ToString();} break; case"*": {文本框[7].Text=(值1*值2).ToString();} break; case"/": {文本框[7].Text=(值1/值2).ToString();} break; default: break; } }

7. 刚刚用vs2013写的c语言计算器不输出结果,是不是代码错了

把搭没scanf_s("%d %c %d", &a,&fh,&b);改为
scanf_s("%d %c %d"知毕纳数悔, &a,&fh,1,&b);

8. vs计算器的代码可以算小数字符串

vs计算器的代码可以算小数字符串。根据查询相关资料信息显示vs计算器的代码是一种计算器,所以可以算小数字符串。vs算器实现了基础的数学运算,如丛槐加,减,乘,除首激等任务,主要是通过该程渗芹友序学习vs.net的编程环境。

阅读全文

与vs计算器代码相关的资料

热点内容
桌面云配置文件分离 浏览:505
iphone5如何升级4g网络 浏览:5
团购是在哪个app 浏览:897
打开多个word文档图片就不能显示 浏览:855
腾讯新闻怎么切换版本 浏览:269
app安装失败用不了 浏览:326
桌面文件鼠标点开会变大变小 浏览:536
手机误删系统文件开不了机 浏览:883
微信兔子甩耳朵 浏览:998
android蓝牙传文件在哪里 浏览:354
苹果6s软解是真的吗 浏览:310
c语言代码量大 浏览:874
最新网络卫星导航如何使用 浏览:425
以下哪些文件属于图像文件 浏览:774
zycommentjs 浏览:414
确认全血细胞减少看哪些数据 浏览:265
文件有哪些要求 浏览:484
cad打开时会出现两个文件 浏览:65
什么是转基因网站 浏览:48
手柄设备有问题代码43 浏览:921

友情链接