定义学院人员类Person,多继承(可运行,但有问题)

#include<iostream>
#include<string.h>

using namespace std;
class Person {

public:
    Person(int age ,char name, char sex)
    { 
        this->name[9] = name;
        this->sex[5] = sex;
        this->age = age;
    }
    void getP() { cin >> age >> name >> sex ; }
    void showP() {
        cout <<"名字:"<< name << endl << "年龄:" << age << endl << "性别:" << sex<< endl;
    }
    ~Person(){}
    char name[10];
    char sex[6];
    int age;
};
class Teacher : public Person
{
public:
Teacher(int age, char name, char sex,char position, char course):Person(age,name,sex)
    {
        this->position[19] = position;
       this->course[19] = course;
    }
     void getT() { cin >> age >> name >> sex>>position>>course; }
    void showT(){
        
        cout << "名字:" << name << endl << "年龄:" << age << endl << "性别:" << sex << endl <<"职称:"<< position <<endl<<"课程:"<< course << endl;
    }
    ~Teacher() {}
    char position[20];
    char course[20];
};
class Student :public Person
{
public:
    Student(int age, char name, char sex,char major, char category) :Person(age, name, sex)
    {
        this->major[19] = major;
        this->category[19] = category;
    }

    void getS() { cin >> age >> name >> sex>>major>>category; }

    void showS() {
      
        cout << "名字:" << name << endl << "年龄:" << age << endl << "性别:" << sex << endl <<"专业:"<< major <<endl<<"类型:"<< category << endl;
    }
    ~Student(){}
    char major[20];
    char category[20];
};
class PostDoctor :public Teacher, public Student
{

};

int main()
{
    Person A(33,'李修', '男');
    A.getP();
    A.showP();
    cout<<" "<< endl;
    Teacher B( 30,'杨明','男','教授','数学');
    B.getT();
    B.showT(); 
    cout << " " << endl;
    Student C(19,'唐韵', '男','数学','博士');
    C.getS();
    C.showS();
    return 0;

去除get部分输出为中文乱码

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值