标签:继承与派生
#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; }
标签:继承与派生
原文地址:http://blog.csdn.net/r_misaya/article/details/40182947