实验报告 课程名称 面向对象程序设计 系 别 机械与电子工程系 班 级 N电信-091F 学生姓名 邓建平 07 学 号 24092200003 任课教师 齐 琦 南湖学院教务办 实验五 继承和派生(上) 一、实验目的 理解类的继承概念,能够定义和使用类的继承关系。 掌握派生类的声明与定义方法。 掌握公有、私有和保护派生的访问特性。 二、实验内容 题目一 设计一个大学的类系统,学校中有学生、教师、职员,每种人员都有自己的特性,他们之间又有相同的地方。利用继承机制定义这个系统中的各个类及类上必需的操作。 注意:先对每类人的属性进行分析,看是否有抽象的可能。 代码: #include using namespace std; class person { char *name; int age; public: person() {cout<<"the constructor of class person!\n";} ~person() {cout<<"the dstructor of class person!\n";} }; class student:public person { char *department; int level; public: student() {cout<<"the constructor of class student!\n";} ~student() {cout<<"the constructor of class student!\n";} }; class teacher:public person { char *major; int salary; public: teacher() {cout<<"the constructor of class teacher!\n";} ~teacher() {cout<<"the constructor of class teacher!\n";} }; class personnel:public person { char *position; public: personnel() {cout<<"the constructor of class personnel!\n";} ~personnel() {cout<<"the constructor of class personnel!\n";} }; void main() { student d1; teacher d2; personnel d3; } 题目二: 考虑大学的学生情况,试利用单一继承来实现学生和毕业生两个类,设计相关的数据成员及函数,编程测试继承的情况。 提示:作为学生一定有学号、姓名、性别、学校及名称及入学时间等基本信息,而毕业生除了这些信息外,还应有毕业时间、所获学位的信息,可根据这些内容设计类的数据成员,也可加入一些其他信息,除了设计对数据进行相应操作的成员函数外,还要考虑到成员类型、继承方式,并在 main()函数中进行相应测试。可设计多种继承方式来测试继承的属性。 代码: #include #include using namespace std; class person { char name[20]; int...