任务九:定义一个person类,派生student类,在派生teacher类,并派生当老师的学生。
#include "stdafx.h"
#include <stdio.h>
#include<iostream>
#include<string>
using namespacestd;
class person
{
public:
person(char*n,char*s,inta)
{
{
name= new char[strlen(n)+ 1];
strcpy(name,n);
}
{
sex = newchar[strlen(s)+ 1];
strcpy(sex,s);
}
{
age= a;
}
}
voidprint()

这篇博客介绍了如何使用C++定义一个person类,并从person类派生出student和teacher类,再进一步派生出既是学生也是老师的teacherstudent类。示例代码展示了各个类的构造函数和print方法,用于输出个人信息、年级、授课科目及专业方向。
最低0.47元/天 解锁文章
2358

被折叠的 条评论
为什么被折叠?



