上机实验2(7页).doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《上机实验2(7页).doc》由会员分享,可在线阅读,更多相关《上机实验2(7页).doc(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-上机实验2-第 7 页攀枝花学院实验报告实验课程: Visual C#,NET程序设计 实验项目: 上机实验4 实验日期:2015年4月28日 系:数学与计算机学院 班级: 2013级计算机科学与技术 姓名: 何静 学号: 201310801009 同组人: 指导教师:罗明刚 成绩:实验目的:1. 理解面向对象的概念,掌握C#的定义类和创建对象的方法;2. 区分类的不同数据成员,包括常量,字段,属性的定义方法,并学会控制其可访问性;3. 掌握类的方法成员的声明和调用,理解各种参数在方法中的意义和使用;4. 理解构造函数和析构函数的作用机制.实验仪器设备,药品,器材:Microsoft vis
2、ual studio 2010实验原理:1.熟悉visual 2010的基本操作方法.1. 认真阅读本章相关内容,尤其是案例.2. 实验前进行程序设计,完成源程序的编写任务.3. 反复操作,直到不需要参考教材,能熟练操作为止.实验步骤:见下页实验步骤:1. 设计一个简单的windows应用程序,输入联系人的姓名,电话和Email,单击添加按钮,显示该联系人的相应信息.要求定义一个AddressBook类,包括:(1) .3个私有字段表示姓名,电话和Email;(2) 一个构造函数通过传入的参数对联系人信息初始化;(3) 一个只读属性对姓名读取;(4) 两个可读属性对电话和Email进入读写,当
3、用户没有输入电话或Email时,读出的值为未输入;(5) 一个方法对该联系人的相应信息进行显示.实验源程序如下: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;namespace _9 public partial class Form1 : Form public Form1() Initia
4、lizeComponent(); private void button1_Click(object sender, EventArgs e) string name = txtname.Text; string phone = txtphone.Text; if (phone = ) phone = null; string email = txtemail.Text; if (email = ) email = null; AddressBook a = new AddressBook(name,phone,email); txtmessage.Text = a.getMessage();
5、 class AddressBook private string name; private string phone; private string email; public AddressBook(string name, string phone, string email) this.name = name; this.phone = phone; this.email = email; public string Name get return name; public string Phone get if (phone = null) return 未输入; else ret
6、urn phone; set phone = value; public string Email get if (email = null) return 未输入; else return email; set email = value; public string getMessage() return string.Format(姓名:0n电话:1nEmail:2, Name, Phone, Email);实验截图:2. 自定义一个时间类,该类包括小时,分,秒字段与属性,具有将秒增加1秒的方法.要求定义一个Time类,包括:(1) .3个私有字段表示时,分,秒;(2) 两个构造函数,一
7、个通过传入的参数对时间初始化,另一个获取系统当前的时间;(3) 3个只读属性对时分秒的读取;(4) 一个方法用于对秒增加1秒.实验源程序如下: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;namespace _11 public partial class Form1 : Form publi
8、c Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) Time t = new Time(); txth.Text = Convert.ToString(t.Hour(); txtm.Text = Convert.ToString(t.Minute(); txts.Text = Convert.ToString(t.Second(); class Time int hour,minute,second; public int Hour() return hour; publ
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 上机 实验
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内