资源预览内容
第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
亲,该文档总共7页全部预览完了,如果喜欢就下载吧!
资源描述
华北水利水电大学 C# 实验报告20142015 学年学年 第第 一一 学期学期 2012 级级 计算机科学与技术计算机科学与技术 专业专业计算器设计201215211 张乐张乐民民一、实验题目:计算器的设计2、实验内容:编写程序,实现简单的数学逻辑运算,即加减乘除运算3、程序设计过程及源代码:设计过程设计过程: a.先通过窗体设计计算器的格式,然后将各个按键改为需要的名称。 b.对各个按键进行程序编写,计算器中有不同种类型的键,所以对于不同的应 不同对待。 c.编写完毕,运行程序源代码源代码: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 WindowsFormsApplication1public partial class Form1 : Formpublic Form1()InitializeComponent();private void button_1_Click(object sender, 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_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 + “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 = textBox1.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 = “;textBox1.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 = “错误“) textBox1.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_del_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 = 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: 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 button_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#.
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号