《C/C++程序设计(二)》实验报告
实验八派生类与继承
姓名: 廖凯 实验日期: 4.27 学号: 201519050221 教师签名: 孙叶枫 班级: 信管15102班 成 绩:
一、实验目的
1) 学习类的的继承,能够定义和使用类的继承关系; 2) 学习派生类的声明与定义方法;
3) 熟悉公有派生和私有派生的访问特性。
二、实验内容及要求
在实验五的student类基础上,定义小学生、中学生、大学生三个继承类; 小学生类增加“年级”数据成员及读写函数,实现全部信息的屏幕输出; 中学生类增加“文理科”数据成员及读写函数,实现全部信息的屏幕输出; 大学生类增加“专业”数据成员及读写函数,实现全部信息的屏幕输出。
三、实验代码(主要代码)
#include #include using namespace std;class student{ public: student(string na,stringn,intch,intma,inteng) { name=na; no=n; chinese=ch; math=ma; english=eng; tatol=0; }
void print() {cout<<\"姓名:\"<private: string name; string no; intchinese; int math; intenglish;- 1 -
英语: inttatol; };
classprimary:public student{ public: int form; primary(string na,stringn,intch,intma,inteng,intfo):student(na,n,ch,ma,eng) {form=fo;} void print() {student::print(); cin>>form; cout<<\"form:\"<