欢迎来到天天文库
浏览记录
ID:38675229
大小:106.81 KB
页数:5页
时间:2019-06-17
《实验一 继承与多态编程练习》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验报告姓名:孟凡响学号:115767日期:2014-01-02实验名称:实验一继承与多态编程练习成绩:一、实验目的及要求实验目的1.理解面向对象思想,体会面向对象思想在编程中的应用。2.掌握VisualC#.NET类的创建(成员,方法,属性),类的继承,类的多态性及类的方法的重载。3.理解继承的含义,掌握派生类的定义方法和实现;4.编写体现类的继承性(成员变量,成员方法,成员变量隐藏)的程序;5.编写体现类多态性(成员方法重载,构造方法重载)的程序。实验要求1.写出程序,并调试程序,要给出测试数据和实验结果。2.整理上机步骤,总结经验和
2、体会。3.完成实验日志和上交程序。二、实验环境WindowsXP操作系统,Visualstudio.net2005三、实验源程序及关键代码解释Using指令集:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;定义Employee类publicclassEmployee{protectedstringname;privatestringsexy;privateintsalary;privatestringdate;privatestringdepartment;pri
3、vatestringtelnum;publicEmployee(){}publicEmployee(string[]args){name=args[0];sexy=args[1];salary=Convert.ToInt32(args[2]);date=args[3];department=args[4];telnum=args[5];}//virtual关键字,方法可以重写publicvirtualvoidDisplay(){Console.WriteLine("Name:{0}",name);Console.WriteLine("Se
4、xy:{0}",sexy);Console.WriteLine("Salary:{0}",salary);Console.WriteLine("Date:{0}",date);Console.WriteLine("Department:{0}",department);Console.WriteLine("Telephone:{0}",telnum);}}定义Employer类,继承基类EmployeepublicclassEmployer:Employee{privatestringposition;privatestringpromo
5、te_date;privatestringnumber;privatestring[]Ename=newstring[50];publicEmployer(string[]args):base(args){position=args[6];promote_date=args[7];number=args[8];for(inti=0;i6、play();Console.WriteLine("Position:{0}",position);Console.WriteLine("Promote_date:{0}",promote_date);Console.WriteLine("Numberofemployee:{0}",number);for(inti=0;i7、er的构造函数和方法并显示:publicclassClass1{staticvoidMain(string[]args){Console.WriteLine("----------------软件051------孔令民------051023----------------------");string[]employee1=newstring[50];Console.WriteLine("Pleaseinputimformationofemployee:");Console.WriteLine("(name,sexy,salary,d8、ate,department,telephonenumber)");employee1=Console.ReadLine().Split('');//调用Employee构造函数Employe
6、play();Console.WriteLine("Position:{0}",position);Console.WriteLine("Promote_date:{0}",promote_date);Console.WriteLine("Numberofemployee:{0}",number);for(inti=0;i7、er的构造函数和方法并显示:publicclassClass1{staticvoidMain(string[]args){Console.WriteLine("----------------软件051------孔令民------051023----------------------");string[]employee1=newstring[50];Console.WriteLine("Pleaseinputimformationofemployee:");Console.WriteLine("(name,sexy,salary,d8、ate,department,telephonenumber)");employee1=Console.ReadLine().Split('');//调用Employee构造函数Employe
7、er的构造函数和方法并显示:publicclassClass1{staticvoidMain(string[]args){Console.WriteLine("----------------软件051------孔令民------051023----------------------");string[]employee1=newstring[50];Console.WriteLine("Pleaseinputimformationofemployee:");Console.WriteLine("(name,sexy,salary,d
8、ate,department,telephonenumber)");employee1=Console.ReadLine().Split('');//调用Employee构造函数Employe
此文档下载收益归作者所有