已阅读5页,还剩30页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验一: VS 环境认识和程序设计初步1.开发一个控制台应用程序,输出你的姓名和学号namespace ConsoleApplication1 class Program static void Main(string args) Console.WriteLine(my name is:zhonghua hong); Console.WriteLine(my is is 2014); Console.Read(); 2. 开发一个WINDOWS应用程序,实现加法计算和清除功能namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) textBox3.Text = (int.Parse(textBox1.Text) + int.Parse(textBox2.Text).ToString(); private void button2_Click(object sender, EventArgs e) textBox1.Text = ; textBox2.Text = ; textBox3.Text = ; 3.新建一个form窗体作为启动窗体,并在窗体上显示“学号,姓名”实验二: C#编程语言基础_上机1. 用控制台应用程序编写一个简单的学生成绩统计系统成绩:90,80,67,87,92,57,77,79,95,99;级别:优、良、中、差;条件:=90 8089 6079 =59;用数组存储成绩:循环判断(if、switch、for);输出优、良、中、差所占成绩的百分比(WriteLine);输出成绩排序(从高到低排序)namespace ConsoleApplication1 class Program static void Main(string args) int score; score=new int1090,80,67,87,92,57,77,79,95,99; int numA=0,numB=0,numC=0,numD=0,num=0; /*for(int i=0;i10;i+) Console.WriteLine (score0,1,i,scorei); */ for (int i = 0; i =90) numA+; else if(scorei=80) numB+; else if(scorei=60) numC+; else numD+; for (int i=0;iscore.Length;i+) switch(scorei/10) case 10: case 9:numA+;break; case 8:numB+;break; case 7: case 6:numC+;break; default:numD+;break; Console.WriteLine(numA:0 %,( 100*numA / score.Length) ); Console.WriteLine(numB:0 %, (100*numB/ score.Length) ); Console.WriteLine(numC:0 %, (100*numC/ score.Length) ); Console.WriteLine(numD:0 %, (100*numD / score.Length) ); /*Console.WriteLine (Original Score); for (int i = 0; i 10; i+) Console.WriteLine(score0,1, i, scorei); */ for (int i = 1; i score.Length; i+) for (int j = 0; j score.Length - i; j+) if (scorej scorej + 1) num = scorej; scorej = scorej + 1; scorej + 1 = num; Console.WriteLine(Original Score); for (int i = 0; i 10; i+) Console.WriteLine(score0,1, i, scorei); Console.ReadKey(); 2. 用windows应用程序设计一个存款计算器(1)利息计算:利息 p*(1+i)N 本金(2)算法流程描述:(a)从用户输入界面中分别提取存款年限、存款本金、年利率;(b)依据公式(1)计算利息总额;(c)计算总的帐户金额 ;(4)将所有要求输出的数据拼凑成符合格式要求的字符串,并输出。namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) float bj = float.Parse(textBox1.Text); float cq = float.Parse(textBox2.Text); float nll= float.Parse(textBox3.Text); double syl = bj*Math.Pow(1 + 0.01 * nll, cq); label4.Text = 本金: + bj + n存期: + cq + n年利率 + nll + n总收益 + syl; 实验四 控制程序设计1.实现在TextBox输入0-9数值,在MessageBox中输出大写汉字namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int sum = int.Parse(textBox1.Text); switch (sum) case 0: MessageBox.Show(零); break; case 1: MessageBox.Show(壹); break; case 2: MessageBox.Show(贰); break; case 3: MessageBox.Show(叁); break; case 4: MessageBox.Show(肆); break; case 5: MessageBox.Show(伍); break; case 6: MessageBox.Show(陆); break; case 7: MessageBox.Show(柒); break; case 8: MessageBox.Show(捌); break; case 9: MessageBox.Show(玖); break; 2.实现登陆界面利用用户名和密码登陆并跳出相应MessageBox,比如可以将用户名设置为admin和shou,密码与用户名相同。 然后跳出相应MessageBoxnamespace WindowsFormsApplication2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if(comboBox1.SelectedIndex = 0) if(textBox2.Text=admin) MessageBox.Show(您输入的用户名和密码正确); else MessageBox.Show(您输入的用户名和密码错误); else if (comboBox1.SelectedIndex = 1) if (textBox2.Text = shou) MessageBox.Show(您输入的用户名和密码正确); else MessageBox.Show(您输入的用户名和密码错误); 3.实现通过在TextBox中输入关键词,查询ListBox中是否有该项名单,如果有用MessageBox告知该内容已查询到,并在ListBox中选中该选项。namespace WindowsFormsApplication3 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) string inStr = textBox1.Text; string strItem; strItem = new string7; for(int i=0;istrItem.Length;i+) strItemi=listBox1.Itemsi.ToString(); for (int i = 0; i strItem.Length; i+) if (strItemi.Contains(inStr) MessageBox.Show(找到了 + + strItemi + ); listBox1.SelectedIndex = i; 实验五 字符串与数组1.移除在richTextBox中输入的字符串中的逗号,namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) private void button1_MouseClick(object sender, MouseEventArgs e) string str = richTextBox1.Text; int num = 0, j = 0; char chfinal; chfinal = new charstr.Length; foreach (char ch in str) if (ch != ,) chfinalj = ch; j+; richTextBox1.Text = new string(chfinal); 2.通过OpenFileDialog选择文件,获得该文件的路径、文件名、后缀名namespace WindowsFormsApplication2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) /openFileDialog1.ShowDialog();(打开文件的另一种方法) OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); string fileAll = dlg.FileName; label5.Text = fileAll; label6.Text=fileAll.Substring(0,fileAll.LastIndexOf()+1); label7.Text = fileAll.Substring(fileAll.LastIndexOf() + 1, fileAll.LastIndexOf(.) - fileAll.LastIndexOf() -1 ); label8.Text = fileAll.Substring(fileAll.LastIndexOf(.) + 1, fileAll.Length - fileAll.LastIndexOf(.) - 1); private void Form1_Load(object sender, EventArgs e) 3.替换文本中的指定字符串namespace WindowsFormsApplication3 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) string str = richTextBox1.Text; richTextBox1.Text = str.Replace(textBox1.Text, textBox2.Text); 实验六:基于WinForms的上机自测系统(按书上的程序做就可以,后半部分没有)实现书pp69-87的上机自测系统namespace selfExam public partial class PrimaryExmForm : Form public PrimaryExmForm() InitializeComponent(); int ExamSecond=0;/考试用时 private void timer1_Tick(object sender, EventArgs e) ExamSecond+; this.ExamTime.Text = ExamSecond.ToString(); private void btnGrade_Click(object sender, EventArgs e) int Score = 0;/总得分 /分别评判每题 if (this.Anwser1.Text = 2000) Score = Score + 10; if (this.Anwser21A.Checked) Score = Score + 10; if (this.Anwser22C.Checked) Score = Score + 10; if (this.Anwser23.Text=PasswordChar) Score = Score + 10; if (this.Anwser24.Text = Text) Score = Score + 10; if (this.Anwser3A.Checked & this.Anwser3B.Checked & this.Anwser3C.Checked & !this.Anwser3D.Checked) Score = Score + 10; this.timer1.Enabled = false;/计时停止 this.btnGrade.Enabled = false;/评分锁定 this.TotalScore.Text = Score.ToString();/显示总得分 private void btnClose_Click(object sender, EventArgs e) this.Close();/调用Close方法关闭窗体PrimaryExmForm 实验七 窗体和控件程序设计1.设计一个简易秒表,通过一个文本框,以213:08的形式显示秒(位数随计数值变化)和毫秒,并且。通过“开始”、“停止”按钮启动或停止计时,通过一个复位按钮复位计数值以便重新开始计数namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); DateTime time = new DateTime(2014, 11, 5, 0, 0, 0); private void button1_Click(object sender, EventArgs e) timer1.Start(); /for (int i = 0; i 10000; i+) / /textBox1.Text = (time.Hour).ToString() + 时 + (time.Minute).ToString() + 分 + (time.Second).ToString() + 秒; / private void timer1_Tick(object sender, EventArgs e) int second = 1; /for (int i = 0; ; i+) / time= time.AddSeconds(second); textBox1.Text = (time.Hour).ToString() + 时 + (time.Minute).ToString() + 分 + (time.Second).ToString() + 秒; / private void button2_Click(object sender, EventArgs e) time = new DateTime(2014, 11, 5, 0, 0, 0); textBox1.Text = (time.Hour).ToString() + 时 + (time.Minute).ToString() + 分 + (time.Second).ToString() + 秒; timer1.Stop(); (2)自行设计一个包含3个功能窗体和1个启动窗体的简单应用程序,每个窗体的功能可以自行设计,但至少包含两种窗体控件并有相应的程序设计,所有窗体通过菜单打开、工具按钮关闭。(Form Fist)namespace WindowsForms public partial class FormFirst : Form public FormFirst() InitializeComponent(); (Form Load)namespace WindowsForms public partial class FormLoad : Form public FormLoad() InitializeComponent(); FormFirst frm1 = new FormFirst(); FormSecond frm2 = new FormSecond(); FormThird frm3 = new FormThird(); private void 打开窗体1ToolStripMenuItem_Click(object sender, EventArgs e) frm1.Show(); private void 打开窗体2ToolStripMenuItem_Click(object sender, EventArgs e) frm2.Show(); private void 打开窗体3ToolStripMenuItem_Click(object sender, EventArgs e) frm3.Show(); private void toolStripButton1_Click(object sender, EventArgs e) frm1.Close(); private void toolStripButton2_Click(object sender, EventArgs e) frm2.Close(); private void toolStripButton3_Click(object sender, EventArgs e) frm3.Close(); (Form Second)namespace WindowsForms public partial class FormSecond : Form public FormSecond() InitializeComponent(); (Form Third)namespace WindowsForms public partial class FormThird : Form public FormThird() InitializeComponent(); 实验八-文件读写本题位于书C#语言windows程序设计上第324页实验4(1).创建一个windows应用程序,其中包含两个TextBox控件(TextBox1,TextBox2)和两个Button控件(Button1),单击Button1(写入),可以字符或字符串格式将TextBox1控件中的文本信息写入到一个文本文件中,单击Button2(读取),可将对应的文本文件中的内容显示在TextBox2。namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() = DialogResult.OK) StreamReader reader = new StreamReader(dlg.FileName); /1.直接读 /richTextBox1.Text = reader.ReadToEnd(); /2.判断 /*while(!reader.EndOfStream) richTextBox1.Text += reader.ReadLine(); */ /3.reader数组,每次读一个字符 char chr = new char1024; while (!reader.EndOfStream) reader.Read(chr, 0, chr.Length); richTextBox1.Text = new String(chr); reader.Close(); private void button2_Click(object sender, EventArgs e) /*SaveFileDialog.dlg = new SaveFileDialog(); if (dlg.ShowDialog() = DialogResult.OK) StreamWriter writer = new StreamWriter(dlg.FileName); writer.Write(richTextBox2.Text); writer.Flush(); writer.Close(); */ (2).创建一个windows应用程序,其中包含一个RichTextBox控件(RichTextBox1)和一个Button控件(Button1),单击Button(读取),可以将一个二进制文件的内容(如一幅图片)显示在RichTextBox1中。namespace WindowsFormsApplication2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() = DialogResult.OK) FileStream fs = new FileStream(dlg.FileName, FileMode.Open); Byte bt = new Bytefs.Length; fs.Read(bt, 0, bt.Length); Graphics gs = pictureBox2.CreateGraphics(); Image img = Image.FromStream(fs); gs.DrawImage(img, 0, 0); fs.Flush(); fs.Close(); private void Form1_Load(object sender, EventArgs e) private void pictureBox2_Click(object sender, EventArgs e) 实验九-GDI+1.pp:246 基于鼠标轨迹画线的程序设计namespace MouseDrawline public partial class Form1 : Form public Form1() InitializeComponent(); /创建绘图对象 g = this.pictureBox1.CreateGraphics(); /定义画线起点X、Y坐标 int LineStartX = 0; int LineStartY = 0; /移动并“按下鼠标”才可画线 bool blDrawLine = false; /定义绘图对象 Graphics g; /初置画线起点以便鼠标移动时画线 private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) if (e.Button = MouseButtons.Left) /画线起点 LineStartX = e.X; LineStartY = e.Y; blDrawLine = true; /画线 private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) /判断是否可以画线 if (blDrawLine) /创建一个2像素宽的蓝色画笔 Pen p = new Pen(Color.Blue,2); /开始画线 g.DrawLine(p, LineStartX, LineStartY, e.X, e.Y); /重置画线起点 LineStartX = e.X; LineStartY = e.Y; /取消画线 private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) blDrawLine = false; /清除画线 private void button1_Click(object sende
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高中数学教师年度述职报告范文
- 企业员工培训体系搭建方案
- 2026届福建省福州市仓山区师范大学附中高三化学第一学期期中达标测试试题含解析
- 福建省尤溪县2026届化学高二第一学期期末复习检测试题含答案
- 2026届吉林省通榆县第一中学高一化学第一学期期中联考试题含解析
- 城市地铁隧道排烟系统施工方案
- 安全管理工作计划方案
- 具身智能+虚拟现实沉浸式体验技术融合方案可行性报告
- 具身智能在老年护理中的场景应用研究报告
- 具身智能+儿童教育中互动机器人情感识别研究报告
- 2025年招教考试化学真题及答案
- 雨课堂在线学堂《现代汉语言语交际》单元考核测试答案
- 车子以租代购合同范本
- 小学六年级科学2025年上学期期中测试试卷(含答案)
- 2023年全国电力安全生产与应急管理知识网络竞赛题库(含答案)
- 2025成都农商银行软件开发岗(Java应用架构)、产品经理岗社会招聘笔试考试备考试题及答案解析
- 2025年泳池水处理设备行业分析报告及未来发展趋势预测
- 人教版(2024)三年级上册数学第五单元线和角课件全套
- 电梯困人自救知识培训课件
- 2025年四川省烟草专卖局(公司)招聘考试笔试试题(含答案)
- 2025年上海市春考语文真题试卷(详析版)
评论
0/150
提交评论