//设计一个人物信息描述类,可以分3种级别存储人物信息(普通信息,学生信息,专业学生信息)
//Person,通用人物描述基类,可以存储各职业人物信息。
//Student,学生描述类,可以存储各种学生人物信息。
//Graduate,专业学生描述类,可以存储专业学生人物信息。
//在主函数测试中使用多态方式不同级别的人物信息。

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;

//创建一个数字基类
#include<iostream>
#include<cstring>
using namespace std;

// 通用人物描述基类
class Person
{
    char *name;
    bool isMale;
    int age;
public:
    Person(char *name, bool isMale, int initage);
    ~Person()
    {
        delete[] name;
    }
    virtual void show()const;
};

// 学生描述类
class Student :public Person
{
    double score;
public:
    Student(char *name, bool isMale, int initAge, double initScore);
    // 实现自己的输出
    virtual void show()const;
};

// 专业学生描述类
class Graduate :public Student
{
    char sy[20];
public:
    Graduate(char *name, bool isMale, int initage, double initScore, char spy[]);
    // 实现自己的输出
    virtual void show() const;
};

//-------------Person实现-------------------
Person::Person(char *nm, bool isM, int a)
    :isMale(isM), age(a)
{
    name = new char[strlen(nm) + 10];
    strcpy(name, nm);
}
void Person::show()const
{
    // 输出通用信息
    cout << name << ",";

    if (isMale)cout << "男";
    else cout << "女";

    cout << "," << age << "岁";
}

//-------------Student实现-------------------
Student::Student(char *nm, bool ism, int a, double s)
    :Person(nm, ism, a), score(s)// 初始化父类 + 自身变量
{
}

void Student::show() const
{
    // 调用父类方法
    Person::show();
    // 实现自己的输出
    cout << "分数:" << score;
}

//-------------Graduate实现-------------------
Graduate::Graduate(char *nm, bool ism, int a, double s, char spy[])
    :Student(nm, ism, a, s)// 初始化父类
{
    strcpy(sy, spy);
}

void Graduate::show() const
{
    // 调用父类方法
    Student::show();
    // 实现自己的输出
    cout << ",专业:" << sy << endl;
}

// 多态方法调用
void fun(Person *person)
{
    person->show();
}

//打印输出
int main(void)
{
    Person   psn("高峰", true, 20);
    Student  st("李红", false, 18, 95);
    Graduate gt("王涛", true, 25, 95, "电子学");
    Person *p[] = { &psn, &st, &gt };

    for (int i = 0; i < 3; i++){
        fun(p[i]);
        cout << endl;
    }

    // 暂停
    system("pause");
    return EXIT_SUCCESS;
}