定义一个人员类Cpeople

来源:百度知道 编辑:UC知道 时间:2024/06/14 00:46:04
定义一个人员类Cpeople,其属性有:姓名、性别、年龄;从中派生出学生类Cstudent,添加属性:学号、入学时间和入学成绩;从Cpeople类在派生出教师类Cteacher,添加属性:职务、部门、工作时间;由Cstudent类派生出研究生类Cgraduate,添加属性:研究方向和导师;由Cgraduate和Cteacher共同派生出助教研究生Cgradonwork,分别定义其中的构造函数和输出函数。并编写主程序进行测试。
我刚学vc++,还不太懂,高手指导!

class Cpeople
{
char[20] name;
char sex;
int age;
}

class Cpeople : public Cstudent
{
int num;
Cstring enterschooltime;
float score[7];可以设置7门课的成绩
}

派生其他类如上,只需添加相应的属性就ok了

#include<iostream>
#include<cstring>
using namespace std;
class CPeople
{
protected:
char name[10];
char sex;
int age;
public:
CPeople(char a[20],char b,int c);
void print();
};
CPeople::CPeople(char a[20],char b,int c)
{
strcpy(name,a);
sex=b;
age=c;
}
void CPeople::print()
{
cout<<"People:"<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Sex: "<<sex<<endl;
cout<<"Age: "<<age<<endl;
}
class CStudent:public CPeople
{
protected:
char Id[20];
char grade[20];