继承与派生 测试 P224

//
// Created by 刘彪 on 2020/3/2.
//继承与派生 测试 P224
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;å

class Person{
    int no;
    char name[10];
public:
    void input(){
        cout<<" 编号:";cin>>no;
        cout<<" 姓名:";cin>>name;
    }
    void disp(){
        cout<<" 编号:"<<no<<endl;
        cout<<" 姓名:"<<name<<endl;
    }
};

class student:public Person{
    char depart[6];
    int degree;
public:
    void input(){
        Person::input();
        cout<<" 班号:";cin>>depart;
        cout<<" 成绩:";cin>>degree;

    }
    void disp(){
        Person::disp();
        cout<<" 班号:"<<depart<<endl;//数组直接可以cin?cout?todo  只针对char适用?
        cout<<" 成绩:"<<degree<<endl;
    }
};
class teacher:public Person{
    char prof[10];
    char depart[10];
public:
    void input(){
        Person::input();
        cout<<" 职称:";cin>>prof;
        cout<<" 部门:";cin>>depart;

    }
    void disp(){
        Person::disp();
        cout<<" 职称:"<<prof<<endl;
        cout<<" 部门:"<<depart<<endl;
    }
};

int main(){
    student s1;
    teacher t1;
    cout<<"输入一个学生数据:\n";s1.input();
    cout<<"输入一个teacher数据:\n";t1.input();
    cout<<"show一个学生数据:\n";s1.disp();
    cout<<"show一个teacher数据:\n";t1.disp();
    return 0;
}

全部评论

相关推荐

求求要我吧:你教育经历放在下面干什么,而且27届还是28届啊()另外看你简历有两面,通常来说投递运营岗位一面简历就够了。另外个人总结要写也放在简历最下面,然后你奖项那里是2019年的哇哈哈,那你究竟投递的是社招还是实习?实习的话你是第几届是肯定要写出来的,社招的话你这个工作经历又太短太花了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务