资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
攀 枝 花 学 院 实 验 报 告实验课程:Visual C#.NET程序设计教程 实验项目:上机实验4 实验日期:2015.04.28系:数计学院 班级:2013级计算机科学与技术 姓名:曹欣 学号:1指导教师:罗明刚 成绩: 1、 实验目的1. 理解面向对象的概念,掌握C#的定义类和创建对象的方法。2. 区分类的不同数据成员,包括常量、字段和属性的定义方法,并学会控制其可访问性。3. 掌握类的方法成员的声明和调用,理解各种参数在方法中的意义和使用。4. 理解构造函数和析构函数的作用机制。2、 实验要求1. 熟悉Visual Studio.Net2010的基本操作方法。2. 认真阅读本章相关内容,尤其是案例。3. 实验前进行程序设计,完成源程序的编写任务。4. 反复操作,直到不需要参考教材、能熟练操作为止。 3、 实验步骤1. 设计一个简单的Windows应用程序,输入联系人的姓名、电话和Email,单击“添加”按钮,显示该联系人的相应信息。要求定义一个AdressBook类,包括:(1)3个私有字段表示姓名、电话和Email;(2) 一个构造函数通过传入的参数对联系人信息初始化;(3) 一个只读属性对姓名读取;(4) 两个可读写属性对电话和Email进入读写,当用户没有输入电话或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 Test2_1 public partial class Form1 : Form public Form1() InitializeComponent(); public 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 return 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); 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 people = new AddressBook(name, phone, email); lblshow.Text = people.GetMessage(); 运行结果如下:2. 自定义一个时间类。该类包括小时、分、秒字段与属性,具有将秒增加1秒的方法。要求定义一个Time类,包括:(1)3个私有字段表示时、分、秒;(2) 两个构造函数,一个通过传入的参数对时间初始化;另一个获取系统当前的时间;(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 Test2_2 public partial class Form1 : Form public Form1() InitializeComponent(); public class Time private int hour; private int minute; private int second; public Time() hour = System.DateTime.Now.Hour; minute = System.DateTime.Now.Minute; second = System.DateTime.Now.Second; public Time(int h, int m, int s) hour = h; minute = m; second = s; public int Hour get return hour; public int Minute get return minute; public int Second get return second; public void AddSecond() second+; if (second 60) second = second % 60; minute+; if (minute 60) minute = minute % 60; hour+; private void button1_Click(object sender, EventArgs e) Time t = new Time(); txthour.Text =Convert.ToString(t.Hour); txtminute.Text =Convert. ToString(t.Minute); txtsecond.Text =Convert.ToString (t.Second); 运行结果如下:3、 设计一个Windows应用程序,模拟一个简单的银行账户管理系统。完成”创建账户“、”取款“、”存款“和”查询余额“的模拟操作。程序功能如下。(1).当单击”创建用户”按钮时,其中卡号为随I机生成的一个在到之间的值,余额初始化为100。(1) 在”取款”文本框中输入取款金额后,单击取款按钮,如果没有创建账
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号