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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

C#实验综合设计.docx

1、C#实验综合设计贵州大学计算机科学与信息学院C#综合设计题 目 姓 名 学 号 班 级 完成 时间 综合设计学院:计算机科学与信息工程学院 专业:网络工程 班级:网络091姓名学号设计组设计时间2012-6-10指导教师成绩设计项目名称综合设计 设计 目的1. 了解文件流的概念。2. 学会文本文件的读写。3. 学会序列化及二进制随机文件的读写。设计内容1.设计如下窗体,A.要求用户点击添加按钮时将当前学生信息添加到指定文本文件中(如源文件中有内容,不覆盖)。B.输入时,要求采用异常处理,针对输入学号、姓名为空,输入年龄、分数小于0的情况 ,弹出相应的出错对话框进行提示。C.点击显示按钮,将当前

2、文件中内容显示出来。(提示:异常处理时要自定义异常,具体方法见参考程序) 2. A.封装一个学生类对象,将以上程序学生信息采用序列化方式写入二进制文件,并可输入学号随机查找相应记录信息显示在文本框中,查找记录时,也要求用异常处理处理输入学号为空的情况。 设计环境Pc机Visual studio2005设计步骤1. 编写程序2. 运行程序3. 得出实验结果设计程序1.using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace StudentLast sta

3、tic class Program / / 应用程序的主入口点。 / STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(); using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using

4、System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace StudentLast public partial class Form1 : Form string path = G:C#实验StudentLastStudentLastStudentLast.txt; public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) string txt = textBo

5、x1.Text + + textBox2.Text + + textBox3.Text + + textBox4.Text + + textBox5.Text+rn; File.AppendAllText(path, txt); private void button2_Click(object sender, EventArgs e) string mystr = ; FileStream fs = File.OpenRead(path); StreamReader sr = new StreamReader(fs); while (sr.Peek() -1) mystr = mystr +

6、 sr.ReadLine() + rn; sr.Close(); fs.Close(); richTextBox1.Text = mystr; private void textBox1_TextChanged(object sender, EventArgs e) if (textBox1.Text = ) MessageBox.Show(学号为空,请重新输入!); private void textBox2_TextChanged(object sender, EventArgs e) if (textBox2.Text = ) MessageBox.Show(姓名为空,请重新输入!);

7、private void textBox3_TextChanged(object sender, EventArgs e) if (textBox3.Text != 男 & textBox3.Text != 女) MessageBox.Show(性别输入有误,请重新输入!); private void textBox4_TextChanged(object sender, EventArgs e) int age = Convert.ToInt32(textBox4.Text); if (age 1) MessageBox.Show(年龄输入有误,请重新输入!); private void t

8、extBox5_TextChanged(object sender, EventArgs e) int score = 0; if (textBox5.Text != ) if (textBox5.Text != -) score = Convert.ToInt32(textBox5.Text); if (score100) MessageBox.Show(分数输入有误,请重新输入!); private void button3_Click(object sender, EventArgs e) 2.using System;using System.Collections.Generic;u

9、sing System.Linq;using System.Windows.Forms;namespace zhsj static class Program / / 应用程序的主入口点。 / STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(); using System;using System.Collections.Generic;using Syste

10、m.Linq;using System.Text;namespace zhsj class NULL1 : Exception class NULL2 : Exception class NOT1 : Exception class NOT2 : Exception class SN : Exception class NULL3 : Exception class yccl public static bool yc(string sa, string sb, string sc, string sd) if(sa =) throw new NULL1 (); else if(sb=) th

11、row new NULL2(); else if(Convert .ToInt32 (sc)0) throw new NOT1(); else if (Convert.ToDouble(sd) 100) throw new NOT2(); else return true; public static bool yd(string se) if (se = ) throw new NULL3(); else return true; using System;using System.Collections.Generic;using System.Linq;using System.Text

12、;namespace zhsj Serializable class stud public int sno, sage; public string sname, sex; public double score; public stud() public stud(int psno, string psname, string psex, int psage, double pscore) sno = psno; sname = psname; sex = psex; sage = psage; score = pscore; public int no get return sno; s

13、et sno = value; public string name get return sname; set sname = value; public string ssex get return sex; set sex = value; public int age get return sage; set sage = value; ; public double sscore get return score; set score = value; using System;using System.Collections;using System.Collections.Gen

14、eric;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.Serialization;using System.Runtime.Serialization.Formatters.Binary;using System.IO;namespace zhsj public partial class Form1 : Form public Form1

15、() InitializeComponent(); ArrayList st = new ArrayList(); private void Form1_Load(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) try yccl.yc(textBox1.Text, textBox2.Text, textBox4.Text, textBox5.Text); stud s = new stud(Convert.ToInt32(textBox1.Text), textBox2.Tex

16、t, textBox3.Text, Convert.ToInt32(textBox4.Text), Convert.ToDouble(textBox5.Text); st.Add(s); FileStream f = new FileStream(I:C#student.dat, FileMode.Create); BinaryFormatter b = new BinaryFormatter(); b.Serialize(f, st); f.Close(); MessageBox.Show(学生信息添加成功!); if (!comboBox1.Items.Contains(textBox1.

17、Text)&!comboBox1.Items.Contains(s.no) comboBox1.Items.Add(textBox1.Text); catch (NULL1) MessageBox.Show(请输入的学号不能为空!); catch (NULL2) MessageBox.Show(请输入的姓名不能为空!); catch (NOT1) MessageBox.Show(请输入的年龄不能小于0!); catch (NOT2) MessageBox.Show(请输入的分数不能小于0或大于100!); private void button2_Click(object sender, Ev

18、entArgs e) try if(!File .Exists(I:C#student.dat) MessageBox.Show(无学生信息记录,请先添加!); else FileStream f = new FileStream(I:C#student.dat, FileMode.Open); BinaryFormatter b = new BinaryFormatter(); st.Clear(); st = (ArrayList)b.Deserialize(f); f.Close(); textBox6.Text = 学号t姓名t性别t年龄t分数 + rn; foreach (stud

19、s1 in st) textBox6.Text = textBox6.Text + string.Format(0t1t2t3t4, s1.no, s1.name, s1.ssex, s1.age, s1.sscore) + rn; if (!comboBox1.Items.Contains(s1.no)&!comboBox1.Items.Contains(textBox1.Text) comboBox1.Items.Add(s1.no); catch(Exception ex) MessageBox.Show(ex.Message); private void button3_Click(o

20、bject sender, EventArgs e) try yccl.yd(comboBox1.Text); ArrayList stu = new ArrayList(); stud s2 = new stud(); FileStream f = new FileStream(I:C#student.dat, FileMode.Open); BinaryFormatter b = new BinaryFormatter(); stu.Clear(); stu = (ArrayList)b.Deserialize(f); f.Close(); textBox6.Text = 学号t姓名t性别

21、t年龄t分数 + rn; foreach (stud s6 in stu) if (s6.no = Convert.ToInt32(comboBox1.Text) textBox6.Text = textBox6.Text + string.Format(0t1t2t3t4, s6.no, s6.name, s6.ssex, s6.age, s6.sscore) + rn; break; catch (NULL3) MessageBox.Show(学号为空,请先选择学号或正确添加信息!); namespace zhsj partial class Form1 / / 必需的设计器变量。 / p

22、rivate System.ComponentModel.IContainer components = null; / / 清理所有正在使用的资源。 / / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) components.Dispose(); base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方

23、法的内容。 / private void InitializeComponent() this.label1 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button1 = new System.Windows.Forms.Button(); this.textBox5 = new System.Windows.Forms.TextBox(); this.textBox4 = new System.Windows.Forms.TextBox(); t

24、his.textBox3 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); t

25、his.label2 = new System.Windows.Forms.Label(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.button2 = new System.Windows.Forms.Button(); this.textBox6 = new System.Windows.Forms.TextBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.button3 = new System.Windows.Forms.But

26、ton(); boBox1 = new System.Windows.Forms.ComboBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.SuspendLayout(); / / label1 / this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(15, 34); this.label1.Name = label1; thi

27、s.label1.Size = new System.Drawing.Size(41, 12); this.label1.TabIndex = 0; this.label1.Text = 学号:; / / groupBox1 / this.groupBox1.Controls.Add(this.button1); this.groupBox1.Controls.Add(this.textBox5); this.groupBox1.Controls.Add(this.textBox4); this.groupBox1.Controls.Add(this.textBox3); this.groupBox1.Controls.Add(this.textBox2); this.groupBox1.Controls.Add(this.textBox1); this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1