5-2 派生类的构造函数
来源:互联网 发布:c语言qsort函数 编辑:程序博客网 时间:2024/06/11 22:13
5-2 派生类的构造函数
Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic
Problem Description
通过本题目的练习可以掌握派生类构造函数的定义和使用方法。
要求定义一个基类Person,它有3个protected的数据成员:姓名name(char *类型)、性别 sex(char类型)、年龄age(int类型);一个构造函数用于对数据成员初始化;有一个成员函数show()用于输出数据成员的信息。
创建Person类的公有派生类Employee,增加两个数据成员 基本工资basicSalary(int类型) 请假天数leaveDays(int型);为它定义初始化成员信息的构造函数,和显示数据成员信息的成员函数show()。
Input
共5个数据,分别代表姓名、性别、年龄、基本工资、请假天数。
Output
如示例数据所示,共5行,分别代表姓名、年龄、性别、基本工资、请假天数
Example Input
zhangsan m 30 4000 2
Example Output
name:zhangsanage:30sex:mbasicSalary:4000leavedays:2
Hint
Author#include <iostream>#include <cstring>#include <string>using namespace std;class person{ public: person(string s,int a,char c) { name=s; age=a; sex=c; } void show() { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; } protected: string name; char sex; int age;};class employee: public person{ public: employee(string s,int a,char c,int x=0,int y=0):person(s,a,c)//先调用基类构造赋值,这里只对新增成员赋值 { bs=x; ld=y; } void show1() { show(); cout<<"basicSalary:"<<bs<<endl; cout<<"leavedays:"<<ld<<endl; } protected: int bs,ld;};int main(){ int a1,bs1,ld1; string n1; char c1; cin>>n1>>c1>>a1>>bs1>>ld1; employee e1(n1,a1,c1,bs1,ld1); e1.show1(); return 0;}
0 0
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- 5-2 派生类的构造函数
- [2712]5-2 派生类的构造函数
- SDUTOJ 2712 5-2 派生类的构造函数
- SDUT 2712 5-2 派生类的构造函数
- sdut 5-2 派生类的构造函数
- 公司-->超级链接跳转和表单提交,删除的表单提交和删除失败的提示信息
- ItemDecoration详解以及用ItemDecoration实现按字母排序列表
- java常见的四种访问权限
- Linux下关于时间的操作
- 快速排序
- 5-2 派生类的构造函数
- 整合IIS与单个tomcat(共用80端口) -- isapi_redirect篇
- 一个目录下的日志 按照日期统计每日日质量大小
- springmvc(3)----参数绑定
- 那些关于“程序猿”的经典和笑话,据说一般人不会懂
- JAVA正则表达式语法及应用总结
- Android 拍照,选取照片,截取,显示
- cocoaPods 常用的命令行
- keil c51在线调试