5-3 多级派生类的构造函数

5-3 多级派生类的构造函数

Time Limit: 1000MS  Memory Limit: 65536KB
Problem Description

要求定义一个基类3name(char *类型sex(char类型age(int类型创建Employee,增加两个数据成员 基本工资 int类型) 请假天数int型);为它定义初始化成员信息的构造函数,和显示数据成员信息的成员函数创建Manager;增加一个成员 业绩 );为它定义初始化成员信息的构造函数,和显示数据成员信息的成员函数如示例数据所示,共<font face="\"Times" new="" roman,="" serif\"="" style="box-sizing: border-box;">5行,分别代表姓名、年龄、性别、基本工资、请假天数、业绩

Example Input
Jerry m 32 4200 1 100
Example Output
name:Jerry
age:32
sex:m
basicSalary:4200
leavedays:1
performance:100
Hint
 
Author
#include <iostream>

using namespace std;

class Person
{
protected:
    string name;
    char sex;
    int age;
public:
    Person(string n, char s, int a)             //基类构造函数
    {
        name = n;
        sex = s;
        age = a;
    }
};

class Employee : public Person
{
private:
    int basicSalary;
    int leaveDays;
public:
    Employee(string n, char s, int a, int b, int l) : Person(n, s, a)       //派生类构造函数
    {
        basicSalary = b;
        leaveDays = l;
    }
    void display()                                             //派生类输出
    {
        cout << "name:" << name << endl;
        cout << "age:" << age << endl;
        cout << "sex:" << sex << endl;
        cout << "basicSalary:" << basicSalary << endl;
        cout << "leavedays:" << leaveDays << endl;          //这里有个坑,注意以后输出有样例,一定要赋值样例
    }
};

class Manager : public Employee
{
private:
    float performance;
public:
    Manager(string n, char s, int a, int b, int l, float p) : Employee(n, s, a, b, l)
    {
        performance = p;
    }
    void show()
    {
        display();
        cout << "performance:" << performance << endl;
    }

};

int main()
{
    string n;
    char s;
    int a, b, l;
    float p;
    cin >> n >> s >> a >>  b >> l >> p;
    Manager m(n, s, a, b, l, p);
    m.show();
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值