计算器课程设计计算器仿真程序设计.doc
《计算器课程设计计算器仿真程序设计.doc》由会员分享,可在线阅读,更多相关《计算器课程设计计算器仿真程序设计.doc(26页珍藏版)》请在三一办公上搜索。
1、课 程 设 计 说 明 书设计题目: 计算器仿真程序设计指导教师: 魏明军 院 系: 信息工程学院 学生姓名: 黄勇 学 号: 201114600120 专业班级: 11计算机一班 2012年06月25日目 录一、系统概述及设计思想11 系统概述12 系统开发基本目标13 系统开发设计思想1二、关键技术11 #region12 异常处理13 if-else24 MessageBox.Show2三、系统功能设计21 计算器操作界面32 查看菜单界面53 编辑菜单界面64帮助菜单界面7四、各功能代码设计81 计算器操作界面窗体8五、使用说明23六、设计体会23七、参考文献23一、系统概述及设计思想
2、1 系统概述利用该仿真计算器能够进行一些简单的计算,只利用windows窗体创建一个窗体可能与设计窗体的美观性相冲突,所以计算器的许多科学功能无法实现。但是,这些缺点可以通过建立一个次窗体实现这些功能按键,通过添加一些按钮,再调用一些系统提供的数学函数,就可以完善该计算器了,基于这是本报告人的第一个设计程序,就没有实现这些功能按键了。希望大家见谅!2 系统开发基本目标该系统包括以下功能:(1)查看:标准、退出。(2)编辑操作:复制、剪切、粘贴、撤销、全选。(3)软件的开发信息。3 系统开发设计思想(1)采用学校现有的软件和硬件环境以及设计要求开发系统。(2)系统采用模块化程序设计方法,既便于系
3、统功能的各种组合和修改,又便于未参与开发的技术维护人员补充,维护。(3)程序设计符合面向对象的思想和原则。(4)要有良好的程序风格(类、方法及变量等的命名要符合规范;类、方法及字段要有注释;程序有适当缩进)(5)采用文件对数据进行存储。(6)人机界面美观,操作方便、实用。二、关键技术1.#region通过在目标代码的前加上#region,在目标代码之后加上#endregion,可以很好地分类各代码使各功能代码清楚易懂,使程序设计更具有层次。2.异常处理利用try-catch结构捕获异常,及时的修改程序,完善程序,减少异常的出现,保证程序正常运行。3. if-else 结构语句利用if-else
4、 结构语句,让程序正确执行各代码,从而达到实现各功能的目的,使程序更具条理性。 4. MessageBox.ShowMessageBox.Show 让程序更好地实现人机交互,醒目,可以减轻人的视觉疲劳,让程序更具趣味性。三、系统功能设计1.计算器操作界面该窗体完成大部分的系统功能,包括复制、剪切、粘贴、全选、撤消和退出等功能。设计如下:向主窗体中添加一个MainMenu控件、一个Timer控件、,添加MainMenu的子菜单(“查看”菜单包括“标准”和“退出”子菜单,“编辑”菜单包括“复制”、“粘贴”、“剪切”、“撤消”和“全选”子菜单,“帮助”菜单包括“关于计算器”子菜单),设置各个控件的属
5、性如表1所示,设置完毕后的主程序界面如图1所示。图1计算器系统主界面表1 控件对象属性列表对象属性设置值控件功能calculatorText黄勇专用计算器窗口标题栏的显式内容calculatorStartPositionCenterScreen运行程序时,使窗体在屏幕中间生成resultTextBoxText0初始化后,该框内显示的值为0resultTextBoxMultilineTrue可以窗体下拉至适宜位置calculatorIcon为计算器添加图标calculatorForecolor可以根据个人喜好,选择字体颜色calculatorFont可以根据个人喜好,设置字体颜色calculat
6、orbackcolor可以根据个人喜好,设置窗体背景颜色lableText在特定的位置显示想要显示的内容ButtonText在Button上显示按键的功能图2计算器系统的“查看”菜单图3计算器系统的“编辑”菜单图4计算器系统“帮助”菜单四、各功能代码设计1 主窗体代码实现using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Wi
7、ndows.Forms;using System.IO;namespace calculator public partial class calculator : Form public string number; public double number1, number2; public double a; public calculator() InitializeComponent(); /初始化 private void calculator_Load(object sender, EventArgs e) this.resultTextBox.Text = 0; /退出 pri
8、vate void exitXToolStripMenuItem_Click(object sender, EventArgs e) Application.Exit(); #region 数字键 0 - 9 private void button25_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button25.Text; else this.resultTextB
9、ox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 + 0); private void button21_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button21.Text; else this.resultTextBox.Text = Convert.ToStrin
10、g(Convert.ToDouble(this.resultTextBox.Text) * 10 + 1); private void button22_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button22.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.r
11、esultTextBox.Text) * 10 + 2); private void button23_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button23.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 +
12、 3); private void button16_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button16.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 + 4); private void button1
13、7_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button17.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 + 5); private void button18_Click(object sender, Ev
14、entArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button18.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 + 6); private void button11_Click(object sender, EventArgs e) if (this.resul
15、tTextBox.Text.IndexOf(.) != -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button11.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 + 7); private void button12_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.)
16、!= -1) this.resultTextBox.Text = this.resultTextBox.Text + this.button12.Text; else this.resultTextBox.Text = Convert.ToString(Convert.ToDouble(this.resultTextBox.Text) * 10 + 8); private void button13_Click(object sender, EventArgs e) if (this.resultTextBox.Text.IndexOf(.) != -1) this.resultTextBox
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算器 课程设计 仿真 程序设计

链接地址:https://www.31ppt.com/p-2391186.html