实验名称
C#实现四则计算器
需求:实现加减乘除四则计算,除零结果为零。
给出设计思路与实现代码。
提交代码与设计文档。
2.实验内容
2)源程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int s;//运算符的标识符
private double x, y;//运算数
private string num; //进行计算的数字
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "";//初始状态下输入框为0
label1.Text = "";//初始状态下标签框置空
}
//输入框
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
//小数点按钮设置
private void dot_Click(object sender, EventArgs e)
{
num += this.dot.Text;
textBox1.Text = num;
}
//数字按钮设置0-9
private void zero_Click(object sender, EventArgs e)
{
num += this.zero.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void one_Click(object sender, EventArgs e)
{
num += this.one.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void two_Click(object sender, EventArgs e)
{
num += this.two.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void three_Click(object sender, EventArgs e)
{
num += this.three.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void four_Click(object sender, EventArgs e)
{
num += this.four.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void five_Click(object sender, EventArgs e)
{
num += this.five.Text;
textBox1.Text = num;
label1.Text &
C#实现四则计算器
需求:实现加减乘除四则计算,除零结果为零。
给出设计思路与实现代码。
提交代码与设计文档。
2.实验内容
2)源程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int s;//运算符的标识符
private double x, y;//运算数
private string num; //进行计算的数字
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "";//初始状态下输入框为0
label1.Text = "";//初始状态下标签框置空
}
//输入框
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
//小数点按钮设置
private void dot_Click(object sender, EventArgs e)
{
num += this.dot.Text;
textBox1.Text = num;
}
//数字按钮设置0-9
private void zero_Click(object sender, EventArgs e)
{
num += this.zero.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void one_Click(object sender, EventArgs e)
{
num += this.one.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void two_Click(object sender, EventArgs e)
{
num += this.two.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void three_Click(object sender, EventArgs e)
{
num += this.three.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void four_Click(object sender, EventArgs e)
{
num += this.four.Text;
textBox1.Text = num;
label1.Text = textBox1.Text;
}
private void five_Click(object sender, EventArgs e)
{
num += this.five.Text;
textBox1.Text = num;
label1.Text &