《C语言程序设计》设计报告
- 格式:docx
- 大小:18.75 KB
- 文档页数:13
中南大学本科生课程设计(实践)任务书、设计报告(C++语言程序设计)题目计算器的设计学生姓名文杨滔指导教师刘雄鹰学院机电工程学院专业班级车辆一班学生学号计算机基础教学实验中心2016年 6 月 30 日计算器的设计摘要:为提高学生所学C++语言程序设计基础综合运用、设计、编程及动手能力,使学生能够在已学的基础上自学地提高扩展自我知识的技能,掌握自我表达、书写组织和总结。
特要求用Microsoft Visual Studio 2010完成CLR窗体应用程序。
自己选择一个计算窗口应用程序。
完成系统需求分析,即功能和数据需求,并进行系统设计即功能模块设计、界面设计以及编程。
系统调试完后编写设计报告。
关键词:Microsoft Visual Studio 2010 CLR窗体应用程序计算窗口1计算器系统开发设计思想根据课程设计的要求,我们的目的是用Microsoft Visual Studio 2010完成CLR窗体应用程序,设计出一个计算或绘图类窗口应用程序,要求:功能:1)用窗体及控件进行数据的输入和输出2)输入方便和可靠。
3)结果正确。
界面设计1) 使用方便2) 操作简单3) 美观通过本课程设计,提高我们所学C++语言程序设计基础综合运用、设计、编程及动手能力,能够在已学的基础上自学地提高扩展自我知识的技能,掌握自我表达、书写组织和总结。
初步培养通过面向对象的思想解决问题的能力,熟悉软件开发过程,增强对相关专业知识的感性认识,掌握基本软件开发技能,提高应用所学知识在实践中发现问题、分析问题和解决问题的能力。
2计算器系统功能及系统设计介绍使用Visual Studio可以制作出很多软件,今天我使用Visual Studio制止小型计算器,制作成功后可以把自己制作计算器放在桌面上供自己使用;更可以根据自己的需求制作各种各样的计算器。
我今天制作的是简单的计算器,复杂的可以在简单的基础上开发。
我选择的题目是设计一个科学计算器(包括三角函数、指数函数等等基本函数计算)的窗体应用程序。
●●a)创建项目:在Microsoft Visual Studio 2010 C#中,建立一个新工程,创建一个新的对话框。
b)计算机界面设计:1.向Form1中添加一个textbox和21个button按钮;2.修改button按钮的text属性,如图所示:c)数字键及小数点代码设计:private void button1_Click(object sender, EventArgs e){textBox1.Text = textBox1.Text + "1";}private void button2_Click(object sender, EventArgs e) {textBox1.Text = textBox1.Text + "2";}private void button3_Click(object sender, EventArgs e) {textBox1.Text = textBox1.Text + "3";}private void button4_Click(object sender, EventArgs e) {textBox1.Text = textBox1.Text + "4";}private void button5_Click(object sender, EventArgs e) {textBox1.Text = textBox1.Text + "5";}private void button6_Click(object sender, EventArgs e) {textBox1.Text = textBox1.Text + "6";}private void button7_Click(object sender, EventArgs e) {textBox1.Text = textBox1.Text + "7";private void button8_Click(object sender, EventArgs e){textBox1.Text = textBox1.Text + "8";}private void button9_Click(object sender, EventArgs e){textBox1.Text = textBox1.Text + "9";}private void button10_Click(object sender, EventArgs e){textBox1.Text = textBox1.Text + "0";}private void button11_Click(object sender, EventArgs e){textBox1.Text = textBox1.Text + ".";}d)加减乘除算法的实现:“+”将控件名为button12更名为“+”,并输入以下程序: private void button12_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;“-”将控件名为button13更名为“-”,并输入以下程序:private void button13_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}“*”将控件名为button14更名为“x”,并输入以下程序:private void button14_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}“/”将控件名为button15更名为“/”,并输入以下程序:private void button15_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}e)三角函数等基本初等函数算法的实现:“sinx”将控件名为button16更名为“sin”,并输入以下程序:private void button16_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}“cosx”将控件名为button17更名为“cos”,并输入以下程序: private void button17_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}“tanx”将控件名为button18更名为“tan”,并输入以下程序: private void button18_Click(object sender, EventArgs e) {Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}“lgx”将控件名为button19更名为“lg”,并输入以下程序: private void button19_Click(object sender, EventArgs e){Button btn = (Button)sender;textBox1.Text = textBox1.Text + btn.Text ;}f)显示结果的算法实现将控件名为button20更名为“=”,并输入以下程序:private void button20_Click(object sender, EventArgs e){try{double d_result;string s_txt = textBox1.Text;int space= s_txt.IndexOf(' ');string s1 = s_txt.Substring(0, space);char operation = Convert.ToChar(s_txt.Substring((space+ 1), 1));string s2 = s_txt.Substring(space + 3);double arg1 = Convert.ToDouble(s1);double arg2 = Convert.ToDouble(s2);switch (operation){case '+':d_result = arg1 + arg2;break;case '-':d_result = arg1 - arg2;break;case 'x':d_result = arg1 * arg2;break;case '/':if (arg2 == 0){//MessageBox.Show("错误");throw new ApplicationException();}else{d_result = arg1 / arg2;}break;default:throw new ApplicationException();}textBox1.Text = d_result.ToString();}catch{double d;double pi =Math .PI;string s_txt = textBox1.Text;int space = s_txt.IndexOf(' ',1);char operation = Convert.ToChar(s_txt.Substring((0),1));string s2 = s_txt.Substring(space+1);double arg2 = Convert.ToDouble(s2);double a = arg2 * pi / 180;switch (operation){case 's':textBox1.Text = d.ToString();break;case 'c':textBox1.Text = d.ToString();break;case 't':textBox1.Text = d.ToString();break;case 'l':textBox1.Text = d.ToString();break;}}g)清除的算法实现将控件名为button21更名为“del”,并输入以下程序:private void button21_Click(object sender, EventArgs e){textBox1.Text = "";}h)调试与运行:3.计算器系统开发的体会我是一个平时不怎么玩电脑的人,对编程一窍不知,在刚开始做的时候,对于窗体应用程序这方面的操作是丝毫不懂,后来听老师讲课,以及自己在实践书上找到相关的知识,才渐渐的知道做简易计算器的大概步骤,首先打窗体应用程序。