皇室战争删除存档:用C++编写一道加减乘除计算器的程序 ?

来源:百度文库 编辑:高校问答 时间:2024/04/29 09:00:45
怎么编写请问?急用~~

以下是一个C#计算器的源码,我写有注释,你可以看下思想,把它换成VC++的

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
bool blnClear,blnFirstOpen; //布尔类型用来判断清除与否,以及第一个显示字符
string strOper; //通过获取strOper的值来决定运算
double dblAcc; //运算数A
double dblSec; //运算数B
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button bPlus;
private System.Windows.Forms.Button bSub;
private System.Windows.Forms.Button bMul;
private System.Windows.Forms.Button bDiv;
private System.Windows.Forms.Button bDot;
private System.Windows.Forms.Button bEqu;
private System.Windows.Forms.Button bClr;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
dblAcc=0;
dblSec=0;
blnClear=true;
blnFirstOpen=true;
strOper=new string('=',1);
}

//判断运算符
private void calc()
{
switch(strOper)
{
case "+":
dblAcc=dblAcc+dblSec;
break;
case "-":
dblAcc=dblAcc-dblSec;
break;
case "*":
dblAcc=dblAcc*dblSec;
break;
case "/":
dblAcc=dblAcc/dblSec;
break;
}
strOper="=";
blnFirstOpen=true;
textBox1.Text=Convert.ToString(dblAcc);
dblSec=dblAcc;
}

//小数点的操作
private void btn_clk(object obj,EventArgs ea)
{
if(blnClear)
textBox1.Text="";
Button b3=(Button)obj;
textBox1.Text+=b3.Text;
if(textBox1.Text==".")
textBox1.Text="0.";
dblSec=Convert.ToDouble(textBox1.Text);
blnClear=false;
}

//运算符按纽都要调用的事件
private void btn_oper(object obj,EventArgs ea)
{
Button tmp=(Button)obj;
strOper=tmp.Text;
if(blnFirstOpen)
dblAcc=dblSec;
else
calc();
blnFirstOpen=false;
blnClear=true;
}

//等号运算
private void ben_equ(object obj,EventArgs ea)
{
calc();
}

//清除按纽操作
private void clear()
{
dblAcc=0;
dblSec=0;
blnFirstOpen=true;
textBox1.Text="";
textBox1.Focus();
}

//清除按纽
private void btn_clr(object obj,EventArgs ea)
{
clear();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.bPlus = new System.Windows.Forms.Button();
this.bSub = new System.Windows.Forms.Button();
this.bMul = new System.Windows.Forms.Button();
this.bDiv = new System.Windows.Forms.Button();
this.bDot = new System.Windows.Forms.Button();
this.bEqu = new System.Windows.Forms.Button();
this.bClr = new System.Windows.Forms.Button();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 24);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.textBox1.Size = new System.Drawing.Size(248, 21);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 96);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(32, 23);
this.button1.TabIndex = 1;
this.button1.Text = "0";
this.button1.Click += new System.EventHandler(this.btn_clk);
//
// button2
//
this.button2.Location = new System.Drawing.Point(56, 96);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(32, 23);
this.button2.TabIndex = 2;
this.button2.Text = "1";
this.button2.Click += new System.EventHandler(this.btn_clk);
//
// button3
//
this.button3.Location = new System.Drawing.Point(96, 96);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(32, 23);
this.button3.TabIndex = 3;
this.button3.Text = "2";
this.button3.Click += new System.EventHandler(this.btn_clk);
//
// button4
//
this.button4.Location = new System.Drawing.Point(16, 128);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(32, 23);
this.button4.TabIndex = 4;
this.button4.Text = "3";
this.button4.Click += new System.EventHandler(this.btn_clk);
//
// button5
//
this.button5.Location = new System.Drawing.Point(56, 128);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(32, 23);
this.button5.TabIndex = 5;
this.button5.Text = "4";
this.button5.Click += new System.EventHandler(this.btn_clk);
//
// button6
//
this.button6.Location = new System.Drawing.Point(96, 128);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(32, 23);
this.button6.TabIndex = 6;
this.button6.Text = "5";
this.button6.Click += new System.EventHandler(this.btn_clk);
//
// button7
//
this.button7.Location = new System.Drawing.Point(16, 160);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(32, 23);
this.button7.TabIndex = 7;
this.button7.Text = "6";
this.button7.Click += new System.EventHandler(this.btn_clk);
//
// button8
//
this.button8.Location = new System.Drawing.Point(56, 160);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(32, 23);
this.button8.TabIndex = 8;
this.button8.Text = "7";
this.button8.Click += new System.EventHandler(this.btn_clk);
//
// button9
//
this.button9.Location = new System.Drawing.Point(96, 160);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(32, 23);
this.button9.TabIndex = 9;
this.button9.Text = "8";
this.button9.Click += new System.EventHandler(this.btn_clk);
//
// button10
//
this.button10.Location = new System.Drawing.Point(16, 192);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(72, 23);
this.button10.TabIndex = 10;
this.button10.Text = "9";
this.button10.Click += new System.EventHandler(this.btn_clk);
//
// bPlus
//
this.bPlus.Location = new System.Drawing.Point(160, 96);
this.bPlus.Name = "bPlus";
this.bPlus.Size = new System.Drawing.Size(48, 23);
this.bPlus.TabIndex = 11;
this.bPlus.Text = "+";
this.bPlus.Click += new System.EventHandler(this.btn_oper);
//
// bSub
//
this.bSub.Location = new System.Drawing.Point(160, 128);
this.bSub.Name = "bSub";
this.bSub.Size = new System.Drawing.Size(48, 23);
this.bSub.TabIndex = 12;
this.bSub.Text = "-";
this.bSub.Click += new System.EventHandler(this.btn_oper);
//
// bMul
//
this.bMul.Location = new System.Drawing.Point(160, 160);
this.bMul.Name = "bMul";
this.bMul.Size = new System.Drawing.Size(48, 23);
this.bMul.TabIndex = 13;
this.bMul.Text = "*";
this.bMul.Click += new System.EventHandler(this.btn_oper);
//
// bDiv
//
this.bDiv.Location = new System.Drawing.Point(160, 192);
this.bDiv.Name = "bDiv";
this.bDiv.Size = new System.Drawing.Size(48, 23);
this.bDiv.TabIndex = 14;
this.bDiv.Text = "/";
this.bDiv.Click += new System.EventHandler(this.btn_oper);
//
// bDot
//
this.bDot.Location = new System.Drawing.Point(96, 192);
this.bDot.Name = "bDot";
this.bDot.Size = new System.Drawing.Size(32, 23);
this.bDot.TabIndex = 15;
this.bDot.Text = ".";
this.bDot.Click += new System.EventHandler(this.btn_clk);
//
// bEqu
//
this.bEqu.Location = new System.Drawing.Point(216, 96);
this.bEqu.Name = "bEqu";
this.bEqu.Size = new System.Drawing.Size(48, 23);
this.bEqu.TabIndex = 16;
this.bEqu.Text = "=";
this.bEqu.Click += new System.EventHandler(this.ben_equ);
//
// bClr
//
this.bClr.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.bClr.Location = new System.Drawing.Point(216, 128);
this.bClr.Name = "bClr";
this.bClr.Size = new System.Drawing.Size(48, 88);
this.bClr.TabIndex = 17;
this.bClr.Text = "WA";
this.bClr.Click += new System.EventHandler(this.btn_clr);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "退出(&Exit)";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "关于Zkk计算器";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 254);
this.Controls.Add(this.bClr);
this.Controls.Add(this.bEqu);
this.Controls.Add(this.bDot);
this.Controls.Add(this.bDiv);
this.Controls.Add(this.bMul);
this.Controls.Add(this.bSub);
this.Controls.Add(this.bPlus);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Zkk计算器1.02威力加强版";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

private void menuItem2_Click(object sender, System.EventArgs e)
{
MessageBox.Show("05软件2班Zkk倾情奉献~0~","谢谢使用",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}