实验6 继承与派生
一、实验目的
1.理解继承与派生、单继承与多继承的概念;
2.理解基类与派生类的定义及使用方法,派生类对象的定义与初始化方法; 3.理解继承与派生过程中,把派生类作为基类构成类族的概念及虚基类的概念。 二、实验环境
一台PC机,Windows XP操作系统,Visual C++ 6.0开发环境。 三、实验内容
1、由在校人员类(Person)作为基类派生出学生类(Student): 实验步骤:
#include #include using namespace std; class Person{ public: Person(int i,char *n, char s, int a){ ID=i; name=n; sex=s; age=a; }; int getID(){ return ID; } void show(){ cout<<\"ID: \"<class Student:public Person{ public:Student(int i,char *n,char s,int a,float m,float p,float e,float c):Person(i,n,s,a){ math=m; physical=p; english=e; cpp=c; total=math+physical+english+cpp; }
void show(){ Person::show(); cout<<\"math: \"<