首页 > 代码库 > SDUTOJ 2712 5-2 派生类的构造函数

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

#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 派生类的构造函数