根据如下描述编写程序:

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:16:56
其中Person类包括name和age两个数据成员,大学生类Student和职工类Worker从Person类派生,大学生类新增的数据成员是score,职工类新增的数据成员是salary,每个类都有用于显示各数据成员值的成员函数show,设计主函数,定义Student类的对象,对所编程进行测试
用C++写的

/*------------person.h--------------*/
class person{
public:
person();
void show();
void setAge(int);
void setName(char *);

protected:
int age;
char *name;

};

class student:public person{
public:
student();
void show();
void setScore(int);
private:
int score;
};

class worker:person{
private:
float salary;
};

/*---------------main.cpp----------------*/
#include<iostream.h>
#include "person.h"

void studentInitialization(student *pstudent){
pstudent->setAge(22);
pstudent->setName("Jack");
pstudent->setScore(99);
}

void main(){
student jack;

studentInitialization(&jack);

jack.show();
}

person::person(){
age=0;
name=NULL;
}

void person::show (){
cout&