ImageVerifierCode 换一换
你正在下载:

C#实验.docx

[预览]
格式:DOCX , 页数:15 ,大小:35.78KB ,
资源ID:11777486      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-11777486.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C#实验.docx)为本站会员(b****3)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

C#实验.docx

1、C#实验 C#程序设计及应用实 验 报 告班 级: * 姓 名: * 学 号: * 教 师: * 信息工程学院计算机系实验一 小型计算器设计一、实验目的1、了解并掌握常用控件的基本属性;2、了解并掌握控件的基本事件程序书写方法;3、掌握控件基本属性的设置与修改。二、实验内容编写代码实现小型计算器,要求具有加减乘除基本功能,可以实现连续的加减乘除运算(自左向右,不需要考虑算符优先级),要求支持小数运算。以“.”开头的数要转化为以“0.”开头的小数,如果除数为0,要给出提示信息。三、实验环境四、实验步骤using System;using System.Collections.Generic;us

2、ing System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace jisuanqi public partial class Form1 : Form int pos = 0; double temp1 = -1; double temp2 = -1; public Form1() InitializeComponent(); private void Form1_Load(object

3、 sender, EventArgs e) private void textBox1_TextChanged(object sender, EventArgs e) public void addNum(int num) /显示框 textBox1.Text = textBox1.Text + num.ToString(); if (textBox1.Text.Length = 2) /首字为0则去除 if (textBox1 .Text .Substring(0,1)=0 & textBox1 .Text .Substring(1,1) !=.) textBox1 .Text =textB

4、ox1 .Text .Substring(1); /数字输入0到9 private void button1_Click(object sender, EventArgs e) addNum(1); private void button2_Click(object sender, EventArgs e) addNum(2); private void button3_Click(object sender, EventArgs e) addNum(3); private void button4_Click(object sender, EventArgs e) addNum(4); pr

5、ivate void button5_Click(object sender, EventArgs e) addNum(5); private void button6_Click(object sender, EventArgs e) addNum(6); private void button7_Click(object sender, EventArgs e) addNum(7); private void button8_Click(object sender, EventArgs e) addNum(8); private void button9_Click(object send

6、er, EventArgs e) addNum(9); private void button10_Click(object sender, EventArgs e) addNum(0); /添加小数点 private void button11_Click(object sender, EventArgs e) if (textBox1.Text = ) textBox1.Text = 0.; else if (textBox1.Text.IndexOf(.) = 0) MessageBox.Show(只能添加一个小数点); else textBox1.Text = textBox1.Tex

7、t + .; /加减乘除运算 private void button12_Click(object sender, EventArgs e)/+ pos = 1; int index = textBox1.Text.IndexOf(=); if (index = -1) /没有“=”号 temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = textBox1.Text + +; else temp1 = Convert.ToDouble(textBox1.Text.Substring(index + 1); textBox1.Text

8、= temp1.ToString() + +; private void button13_Click(object sender, EventArgs e)/- pos = 2; int index = textBox1.Text.IndexOf(=); if (index = -1) /没有“=”号 temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = textBox1.Text + -; else temp1 = Convert.ToDouble(textBox1.Text.Substring(index + 1); textB

9、ox1.Text = temp1.ToString() + -; private void button14_Click(object sender, EventArgs e)/* pos = 3; int index = textBox1.Text.IndexOf(=); if (index = -1) /没有“=”号 temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = textBox1.Text + X; else temp1 = Convert.ToDouble(textBox1.Text.Substring(index +

10、1); textBox1.Text = temp1.ToString() + X; private void button15_Click(object sender, EventArgs e)/ pos = 4; int index = textBox1.Text.IndexOf(=); if (index = -1) /没有“=”号 temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = textBox1.Text + ; else temp1 = Convert.ToDouble(textBox1.Text.Substring(i

11、ndex + 1); textBox1.Text = temp1.ToString() + ; /等于 事件 private void button17_Click(object sender, EventArgs e) int indexofA; switch (pos) case 1: indexofA = textBox1.Text.IndexOf(+); temp2 = Convert.ToDouble(textBox1.Text.Substring(indexofA + 1); textBox1.Text = textBox1.Text + = + (temp1 + temp2).T

12、oString(); break ; case 2: indexofA = textBox1.Text.IndexOf(-); string bb = textBox1.Text.Substring(indexofA + 1); temp2 = Convert.ToDouble( textBox1.Text.Substring(indexofA + 1); textBox1.Text = textBox1.Text + = + (temp1 - temp2).ToString(); break ; case 3: indexofA = textBox1.Text.IndexOf(X); tem

13、p2 = Convert.ToDouble( textBox1.Text.Substring(indexofA + 1); textBox1.Text = textBox1.Text + = + (temp1 * temp2).ToString(); break ; case 4: indexofA = textBox1.Text.IndexOf(); temp2 = Convert.ToDouble( textBox1.Text.Substring(indexofA + 1); if(temp2=0) MessageBox .Show (除数不能为0!); else textBox1.Tex

14、t = textBox1.Text + = + (temp1 / temp2).ToString(); break ; /清零 private void button16_Click(object sender, EventArgs e) textBox1.Text = 0; temp1 = 0; pos = 0; 5、实验结果可连加,可显示运算过程实验二 多线程售票程序设计一、实验目的1、理解线程的基本概念2、理解线程同步的基本方法3、掌握利用Lock实现线程同步的方法二、实验内容假设有M(0M300)张票,由N(输入,0N800)个线程来实现一个WinForm桌面应用程序实现售票,每次线程

15、运行时都首先检查是否还有票未售出,如果有就按照票号从小到大的顺序售出,同时输出剩余票数。三、实验环境四、实验步骤using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading; namespace goupiaoxitong public partial class

16、 Form1 : Form int M; /票数 int N; /人数 private Object lockthis = new Object(); /用于上锁 private List ticketlist; public Form1() InitializeComponent(); M = Convert.ToInt32(textBox1.Text); /读取控件框的值 N = Convert.ToInt32(textBox2.Text); CheckForIllegalCrossThreadCalls = false; /重点:新创建的线程不能访问UI线程创建的窗口控件 private

17、 void button1_Click(object sender, EventArgs e) /按钮 ticketlist = new List(M); for (int i = 1; i = M; i+) ticketlist.Add(i.ToString().PadLeft(3, 0);/票号3位 listBox2.Items.Clear(); /清空 Thread myThread = new ThreadN;/创建多线程 for (int i = 0; i N; i+) Thread t = new Thread(sell); t.Name = 线程 + i.ToString();

18、myThreadi = t; for (int i = 0; i N; i+) myThreadi.Start(); public void sell() /线程方法 for (int i = 0; i 0) string ticketNo = ticketlist0; string str = Thread.CurrentThread.Name + 买了票 + ticketNo ; ticketlist.RemoveAt (0); str += .剩余 + ticketlist.Count + 张票; listBox2.Items.Add(str); private void listBox

19、2_SelectedIndexChanged(object sender, EventArgs e) private void textBox1_TextChanged(object sender, EventArgs e) private void label3_Click(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e) 五、实验结果6、结果分析注意:控件名是listbox2. CheckForIllegalCrossThreadCalls = false; /重点:新创建的线程不能访问UI线程创建的窗口控件

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2