C++简单时区时间计算程序设计课程设计报告.docx
课程设计报告课程名称: 编程类课程设计 课程题目: 简单时区时间计算程序设计 专业班级: 电子信息工程1101班 姓 名: 学 号: 指导老师: 成 绩: 目 录第一章 前言第二章 课设目的第三章 课设内容及实现的功能第四章 流程图第五章 程序第六章 运行结果图第七章 出现的问题及解决方法 第八章 心得体会及建议第九章 参考文献一、 前言C#是微软公司发布的一种面向对象的、运行于.NET Framework之上的高级程序设计语言。并定于在微软职业开发者论坛(PDC)上登台亮相。C#是微软公司研究员Anders Hejlsberg的最新成果。C#看起来与Java有着惊人的相似;它包括了诸如单一继承、接口、与Java几乎同样的语法和编译成中间代码再运行的过程。但是C#与Java有着明显的不同,它借鉴了Delphi的一个特点,与COM(组件对象模型)是直接集成的,而且它是微软公司 .NET windows网络框架的主角。C#是面向对象的编程语言。它使得程序员可以快速地编写各种基于MICROSOFT .NET平台的应用程序,MICROSOFT .NET提供了一系列的工具和服务来最大程度地开发利用计算与通讯领域。C#使得C+程序员可以高效的开发程序,且因可调用由 C/C+ 编写的本机原生函数,因此绝不损失C/C+原有的强大的功能。因为这种继承关系,C#与C/C+具有极大的相似性,熟悉类似语言的开发者可以很快的转向C#。二、 课设目的1. 掌握Visual Studio语言的调试方法。2. 练习利用Visual Studio C#可视化编程实现一些简单功能。三、课设内容及实现的功能制作简单时区时间计算程序设计。可以实现的功能有:时区时差的换算、秒表、计算器(额外)、单位换算(额外)。关键字部分描述:catch:定义一个代码块,在特定类型异常抛出时,执行块内代码。checked:既是操作符又是语句,确保编译器运行时,检查整数类型操作或转换时出现的溢出。finally:定义一个代码块,在程序控制离开try代码快后执行。参见try和catch。fixed:在一个代码块执行时,在固定内存位置为一个变量指派一个指针。namespace:定义一个逻辑组的类型和命名空间。operator:用来声明或多载一个操作符。out:标识一个参数值会受影响的参数,但在传入方法时,该参数无需先初始化。params:声明一个参数数组。如果使用,必须修改指定的最后一个参数,允许可选参数。readonly:标识一个变量的值在初始化后不可修改。ref:标识一个参数值可能会受影响的参数。throw:抛出一个异常。try:异常处理代码块的组成部分之一。try代码块包括可能会,抛出异常的代码。参阅catch和finally关键字。using:当用于命名空间时,using关键字允许访问该命名空间中的类型,而无需指定其全名。也用于定义finalization操作的范围。部分按钮设计流程图 按钮“0”(其余数字按钮类似)四、流程图开始判断textbox1和textbox2,textbox1<24和textbox2<60textbox1和textbox2不是数字在textbox1和textbox2中输入一个时间(textbox<24,texybox2<60)textbox1>=24或textbox2>=60然后点击纽约,时间就会前移13个小时,再按下迪拜,时间前移4个小时 t时间不正确格式不正确 结束 五、程序Form1using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 课程设计 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) Form2 f2=new Form2(); f2.Show(); private void button2_Click(object sender, EventArgs e) Form3 f3 = new Form3(); f3.Show(); private void button3_Click(object sender, EventArgs e) Form4 f4 = new Form4(); f4.Show(); private void button4_Click(object sender, EventArgs e) Form5 f5 = new Form5(); f5.Show(); private void button5_Click(object sender, EventArgs e) MessageBox.Show("老师辛苦了"); /弹窗 this.Close(); /此窗口关闭 private void Form1_Load(object sender, EventArgs e) Form2/显示的文本string 计算的数值intnamespace 课程设计 public partial class Form2 : Form int num=0, temp=0; int way = 0; /way是决定运算符号的,+1 -2 *3 /4 public Form2() InitializeComponent(); textBox1.Text = "0" private void button7_Click(object sender, EventArgs e) if (way=0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 7; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 7; textBox1.Text = temp.ToString(); private void button13_Click(object sender, EventArgs e) way = 3; textBox1.Text = "0" private void button1_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); /string 转 int num = num * 10 + 1; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 1; textBox1.Text = temp.ToString(); private void button10_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 ; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 ; textBox1.Text = temp.ToString(); private void button2_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 2; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 2; textBox1.Text = temp.ToString(); private void button3_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 3; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 3; textBox1.Text = temp.ToString(); private void button11_Click(object sender, EventArgs e) way = 1; textBox1.Text = "0" private void button4_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 4; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 4; textBox1.Text = temp.ToString(); private void button5_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 5; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 5; textBox1.Text = temp.ToString(); private void button6_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 6; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 6; textBox1.Text = temp.ToString(); private void button12_Click(object sender, EventArgs e) way = 2; textBox1.Text = "0" private void button8_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 8; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 8; textBox1.Text = temp.ToString(); private void button9_Click(object sender, EventArgs e) if (way = 0) num = Convert.ToInt32(textBox1.Text); num = num * 10 + 9; textBox1.Text = num.ToString(); else temp = Convert.ToInt32(textBox1.Text); temp = temp * 10 + 9; textBox1.Text = temp.ToString(); private void button16_Click(object sender, EventArgs e) textBox1.Text = "0" private void button15_Click(object sender, EventArgs e) int i=0; if (way = 1) i = num + temp; else if (way = 2) i = num - temp; else if (way = 3) i = num * temp; else if (way = 4) i = num / temp; way = 0; textBox1.Text = i.ToString(); /显示计算后的结果 int转string private void button14_Click(object sender, EventArgs e) way = 4; textBox1.Text = "0" Form3namespace 课程设计 public partial class Form3 : Form public Form3() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int i=0, j=0; label2.Text = "小时" label3.Text = "分钟" try i = Convert.ToInt32(textBox1.Text); j = 60 * i; textBox2.Text = j.ToString(); catch /处理异常 MessageBox.Show("输入格式不正确"); private void button2_Click(object sender, EventArgs e) int i = 0, j = 0; label2.Text = "米" label3.Text = "厘米" try i = Convert.ToInt32(textBox1.Text); j = 100 * i; textBox2.Text = j.ToString(); catch MessageBox.Show("输入格式不正确"); private void button3_Click(object sender, EventArgs e) int i = 0, j = 0; label2.Text = "平方米" label3.Text = "平方分米" try i = Convert.ToInt32(textBox1.Text); j = 100 * i; textBox2.Text = j.ToString(); catch MessageBox.Show("输入格式不正确"); private void button4_Click(object sender, EventArgs e) int i = 0, j = 0; label2.Text = "立方米" label3.Text = "立方分米" try i = Convert.ToInt32(textBox1.Text); j = 1000 * i; textBox2.Text = j.ToString(); catch MessageBox.Show("输入格式不正确"); private void button5_Click(object sender, EventArgs e) int i = 0, j = 0; label2.Text = "千克" label3.Text = "克" try i = Convert.ToInt32(textBox1.Text); j = 1000 * i; textBox2.Text = j.ToString(); catch MessageBox.Show("输入格式不正确"); private void textBox1_TextChanged(object sender, EventArgs e) private void label2_Click(object sender, EventArgs e) private void Form3_Load(object sender, EventArgs e) Form4namespace 课程设计 public partial class Form4 : Form int hh=0, mm = 0; public Form4() InitializeComponent(); private void button1_Click(object sender, EventArgs e) try hh = Convert.ToInt32(textBox1.Text); mm = Convert.ToInt32(textBox2.Text); if (hh < 24 && mm < 60) hh = (hh + 24 - 13) % 24; /余数 /防止出现负数 textBox3.Text = hh.ToString(); textBox4.Text = mm.ToString(); else MessageBox.Show("时间不正确!"); catch MessageBox.Show("格式不正确!"); private void button2_Click(object sender, EventArgs e) try hh = Convert.ToInt32(textBox1.Text); mm = Convert.ToInt32(textBox2.Text); if (hh < 24 && mm < 60) hh = (hh + 24 - 4) % 24; textBox3.Text = hh.ToString(); textBox4.Text = mm.ToString(); else MessageBox.Show("时间不正确!"); catch MessageBox.Show("格式不正确!"); private void textBox1_TextChanged(object sender, EventArgs e) private void textBox3_TextChanged(object sender, EventArgs e) private void Form4_Load(object sender, EventArgs e) Form5namespace 课程设计 public partial class Form5 : Form int i=0,j=0; public Form5() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (button1.Text = "开始") timer1.Enabled = true; button1.Text = "暂停" else if (button1.Text = "暂停") timer1.Enabled = false; button1.Text = "开始" private void timer1_Tick(object sender, EventArgs e) i+; label1.Text = (i / 3600).ToString() +":"+ (i % 3600 / 60).ToString()+":" + (i % 60).ToString(); private void button2_Click(object sender, EventArgs e) i = 0; timer1