第一题:公有继承 —— 学生信息类
#include "people.h" // People 类定义在这里面 #include第2题:保护继承 —— 学生信息类#include using namespace std; //公有继承 People class Student:public People { public: int SID; void PrintSID(); }; void Student::PrintSID() { //输出 SID cout<<"学号:"< SID=sid; ptr->Name=name; }
#include "people.h" // People 类定义在这里面 #include#include using namespace std; //保护继承 People class Student:protected People { public: int SID; void PrintSID(); //添加一个 Set 函数来设置父类的 Name 成员 friend void Set(int id,string name,Student *ptr); }; void Student::PrintSID() { //输出学号 SID cout<<"学号:"< SID=id; ptr->Name=name; }
第三题:研究生信息类
#include "people.h" //People类定义在这里面 #include#include using namespace std; //私有继承 People 类 class Student :private People { public: int SID; void PrintSID(); //添加一个 Set 函数来设置父类的 Name 成员 void SetName(string name); }; void Student::SetName(string name) { Name=name; } void Student::PrintSID() { //输出学号 SID cout<<"学号:"< SID=sid; ptr->ResearchID=rid; ptr->Set(name); }



