C#简易计算器设计

上传人:206****923 文档编号:41627322 上传时间:2018-05-30 格式:DOC 页数:7 大小:898KB
返回 下载 相关 举报
C#简易计算器设计_第1页
第1页 / 共7页
C#简易计算器设计_第2页
第2页 / 共7页
C#简易计算器设计_第3页
第3页 / 共7页
C#简易计算器设计_第4页
第4页 / 共7页
C#简易计算器设计_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《C#简易计算器设计》由会员分享,可在线阅读,更多相关《C#简易计算器设计(7页珍藏版)》请在金锄头文库上搜索。

1、华北水利水电大学 C# 实验报告20142015 学年学年 第第 一一 学期学期 2012 级级 计算机科学与技术计算机科学与技术 专业专业计算器设计201215211 张乐张乐民民一、实验题目:计算器的设计2、实验内容:编写程序,实现简单的数学逻辑运算,即加减乘除运算3、程序设计过程及源代码:设计过程设计过程: a.先通过窗体设计计算器的格式,然后将各个按键改为需要的名称。 b.对各个按键进行程序编写,计算器中有不同种类型的键,所以对于不同的应 不同对待。 c.编写完毕,运行程序源代码源代码:using System;using System.Collections.Generic;usin

2、g System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication1public partial class Form1 : Formpublic Form1()InitializeComponent();private void button_1_Click(object sender,

3、 EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;textBox1.Text = textBox1.Text + “1“;private void button_0_Click(object sender, EventArgs e)if (textBox1.Text = “0“|textBox1.Text =“错误“) textBox1.Text = “0“;elsetextBox1.Text = textBox1.Text + “0“;private void button_point

4、_Click(object sender, EventArgs e)if (textBox1.Text = “错误“) textBox1.Text = “0“;if(textBox1.Text.IndexOf(“.“)=-1)textBox1.Text = textBox1.Text + “.“;private void button_2_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“)textBox1.Text = “;textBox1.Text = textBox1.Text +

5、 “2“;private void button_3_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;textBox1.Text = textBox1.Text + “3“;private void button_4_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;textBox1.Text = t

6、extBox1.Text + “4“;private void button_5_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;textBox1.Text = textBox1.Text + “5“;private void button_6_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;tex

7、tBox1.Text = textBox1.Text + “6“;private void button_7_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;textBox1.Text = textBox1.Text + “7“;private void button_8_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox

8、1.Text = “;textBox1.Text = textBox1.Text + “8“;private void button_9_Click(object sender, EventArgs e)if (textBox1.Text = “0“ | textBox1.Text = “错误“) textBox1.Text = “;textBox1.Text = textBox1.Text + “9“;private void button_c_Click(object sender, EventArgs e)textBox1.Text = “0“;private void button_d

9、el_Click(object sender, EventArgs e)string str1 = textBox1.Text;int sten = str1.Length;string str2 = null;if (textBox1.Text != “)str2 = str1.Substring(0, sten - 1);textBox1.Text = str2;private int flag = 0;private float firstnum = 0;private void button_add_Click(object sender, EventArgs e)firstnum =

10、 float.Parse(textBox1.Text);flag = 1;textBox1.Text = “0“;private void button_de_Click(object sender, EventArgs e)float secnum = float.Parse(textBox1.Text);switch (flag)case 1: textBox1.Text = (firstnum + secnum).ToString(); break;case 2: textBox1.Text = (firstnum - secnum).ToString(); break;case 3:

11、textBox1.Text = (firstnum * secnum).ToString(); break;case 4: if (secnum = 0) textBox1.Text = “错误“;else textBox1.Text = (firstnum / secnum).ToString(); break;private void button_jian_Click(object sender, EventArgs e)firstnum = float.Parse(textBox1.Text);flag = 2;textBox1.Text = “0“;private void butt

12、on_mul_Click(object sender, EventArgs e)firstnum = float.Parse(textBox1.Text);flag = 3;textBox1.Text = “0“;private void button_chu_Click(object sender, EventArgs e)firstnum = float.Parse(textBox1.Text);flag = 4;textBox1.Text = “0“;四、测试结果(程序运行结果采用截图的方式打印):五、小结(包括收获、心得体会、存在的问题及解决问题的方法、建议等)(包括收获、心得体会、存在的问题及解决问题的方法、建议等)在实验过程中,采用了模块化设计,先进行局部功能的实现,最后再进行归纳综合,各个窗体的设计各有不同,采用了不同的函数,初步设计计算器这一程序,是对所学的一个实践,接下来的时间里,我会继续努力学习,以熟练的掌握 C#.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

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