码迷,mamicode.com
首页 > 其他好文 > 详细

SDUTOJ 2712 5-2 派生类的构造函数

时间:2014-10-17 11:58:55      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:继承与派生

bubuko.com,布布扣
#include<iostream>
#include<string>
using namespace std;
class Person
{
protected:
	char sex;
	int age;
	string name;
public:
	Person(string nam,char s,int a)
	{
		name=nam;
		sex=s;
		age=a;
	}
};
class Employee:public Person
{
private:
	int salary,leave;
public:
	Employee(string nam,char s,int a,int y,int l):Person(nam,s,a)
	{
        salary=y;
		leave=l;
	}
	void show()
	{
		cout<<"name"<<":"<<name<<endl;
		cout<<"age"<<":"<<age<<endl;
		cout<<"sex"<<":"<<sex<<endl;
		cout<<"basicSalary"<<":"<<salary<<endl;
		cout<<"leavedays"<<":"<<leave<<endl;
	}
};
int main()
{
	int a,b,c;
	char e;
	string f;
	cin>>f>>e>>a>>b>>c;
	Employee t(f,e,a,b,c);
	t.show();
	return 0;
}
 

SDUTOJ 2712 5-2 派生类的构造函数

标签:继承与派生

原文地址:http://blog.csdn.net/r_misaya/article/details/40182947

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!