导航菜单
首页 >  mit大学研究生  > 继承的题目

继承的题目

题目描述

定义一个学生基类Student,包括私有数据成员:学校名、姓名、年龄,输出数据成员值的公有成员函数Print()。再定义一个研究生类G_Student,公有继承方式派生于学生类Student,其中新增私有数据成员:导师姓名,并定义输出研究生数据的公有成员函数Print()。实现学生信息的输出。 键盘输入:MIT Kate 20 Smith 输出:MIT大学的Kate年龄20导师是Smith

输入

MIT Kate 20 Smith

输出

MIT大学的Kate年龄20导师是Smith

附ac代码

#include#includeusing namespace std;class student {protected:char* school;char* name;int old;public:student(char* s, char* n, int o){school = new char[strlen(s) + 1];if (school != 0) strcpy(school, s);name = new char[strlen(n) + 1];if (name != 0) strcpy(name, n);old = o;}void Print(){cout > n >> o >> t;G_Student g(s, n, o, t);g.Print();return 0;}

 

相关推荐: