已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验报告姓名: 学号: 日期: 2012年11月15日 实验名称: 实验一 继承与多态编程练习 成绩: 一、实验目的及要求实验目的:1.理解面向对象思想,体会面向对象思想在编程中的应用;2.掌握Visual C#.NET类的创建(成员,方法,属性),类的继承,类的多态性及类的方法的重载。3. 理解继承的含义,掌握派生类的定义方法和实现;4. 编写体现类的继承性(成员变量,成员方法,成员变量隐藏)的程序;5. 编写体现类多态性(成员方法重载,构造方法重载)的程序。实验要求:1.写出程序,并调试程序,要给出测试数据和实验结果。2.整理上机步骤,总结经验和体会。3.完成实验日志和上交程序。二、实验环境Windows XP操作系统,Visual 2005三、实验源程序及关键代码解释1.员工类:using System;using System.Collections.Generic;using System.Text; class Program static void Main(string args) Employee e1=new Employee (EVE,F,6000,2014年7月25日,信息部,123456789); e1.display (); Leader l1= new Leader(EVE,F,6000,2014年7月25日,信息部,123456789,主管, 2015年10月29日, 20); l1 .display (); class Employee protected string name; protected string sex; protected int salary; protected string date; protected string department; protected string tel; public Employee (string name,string sex,int salary,string date,string department,string tel) =name; this .sex =sex ; this .salary =salary ; this .date =date ; this .department =department ; this .tel =tel ; public virtual void display() System .Console .WriteLine(姓名:0,name ); System .Console .WriteLine(性别:0,sex ); System .Console .WriteLine(工资:0,salary ); System .Console .WriteLine(入职日期:0,date ); System .Console .WriteLine(所属部门:0,department ); System .Console .WriteLine(联系电话:0,tel ); class Leader:Employee private string post; private string risedate; private int numb; public Leader (string name,string sex,int salary,string date,string department,string tel,string post,string risedate,int numb):base(name,sex,salary,date,department,tel) this .post =post ; this .risedate =risedate ; this.numb =numb ; public override void display() base.display(); System .Console .WriteLine(提职后信息如下: ); System .Console .WriteLine(职位:0,post ); System .Console .WriteLine(提职时间:0,risedate ); System .Console .WriteLine(管理人数:0,numb ); 2.书店类using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication8 class Program static void Main(string args) TextBook T1=new TextBook (平凡的世界,路遥,100,5); T1.display(); class TextBook private string Title; private string Author; private double Cost; private int Quantity; private double Price; public TextBook (string Title,string Author,double Cost,int Quantity) this .Title =Title ; this .Author =Author ; this .Cost =Cost ; this .Quantity =Quantity ; Price =1.25*Cost /Quantity ; public void display() System.Console.WriteLine(书的信息如下:); System .Console .WriteLine(书名:0,Title ); System .Console .WriteLine(作者:0,Author ); System .Console .WriteLine(批发费用:0,Cost ); System .Console .WriteLine(库存量:0,Quantity ); System .Console .WriteLine(零售价:0,Price ); 3.雇员类using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication9 class Program static void Main(string args) Programmer P1=new Programmer (张三,北辰区,1991.10.29,4000,1000); System .Console .WriteLine (程序员的工资为:0,P1.salary (); Exacute E1=new Exacute (李四,和平区,1990.2.26,5000,2000); System .Console .WriteLine (高管的工资为:0,E1.salary(); Secretary S1=new Secretary(王五,河北区,1991.1.1,3000); System .Console .WriteLine (秘书的工资为:0,S1 .salary(); Worker W1=new Worker(赵六,河东区,1992.2.2,1000); System .Console .WriteLine (清洁工的工资为:0,W1 .salary(); abstract class Employee private string name; private string add; private string birthday; public Employee(string name, string add, string birthday) = name; this.add = add; this.birthday = birthday; public abstract int salary(); class Programmer : Employee private int t,s; public Programmer(string name, string add, string birthday,int s,int t):base(name,add,birthday) this.t=t; this.s=s; public override int salary() return (s + t); class Exacute : Employee private int t,s; public Exacute(string name, string add, string birthday,int s,int t):base(name,add,birthday) this.t=t; this.s=s; public override int salary() return (s + t); class Secretary : Employee private int s; public Secretary(string name, string add, string birthday,int s):base(name,add,birthday) this.s=s; public override int salary() return (s); class Worker : Employee private int s; public Worker(string name, string add, s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/SWSTA 0003-2020供水管网加氯技术指南
- T/SDIE 25-2025 T/SDII 11-2025基于区块链的医疗数据共享安全要求
- T/CZGJ 002-2025地方铁路400MHz数字无线通信系统技术条件
- T/CI 1210-2025软土地基深层加固与沉降控制综合技术规程
- T/AHMT 1-2025纳米级电涡流位移传感器
- T/CNHAW 0015-2025临床应用药物分析检测通用要求
- AI在人文教育中的应用
- 2026学年江苏省启东市一年级语文期末评估冲刺押宝题(详细参考解析)详细答案和解析
- 脚手架搭设与拆除安全作业培训
- Photoshop 综合测试试题(三)及详细参考答案
- 2026年时事政治考题及参考答案
- 4.3 化学键(教案)2022-2023学年高一化学人教版(2019)必修第一册
- 2026年秋新教材统编版九年级上册历史全册教案(含教学反思)
- 施工现场污水沉淀池设计
- 2026人教版五年级数学上册第四单元第3课《平移(2)》课件
- 新版人教版四年级上册数学全册教案(完整版)教学设计含教学反思
- 医院物价管理制度 (三)
- 饮用水水源地保护项目水资源论证报告书
- 26年老年群体心理照护宣教课件
- 2026物业管理行业市场供需分析及投资评估规划分析研究报告
- 仁爱版七年级英语上册单词默写表(2026年)
评论
0/150
提交评论