#include<bits/stdc++.h>
using namespace std;
class worker
{
public:
worker(string IDValue,string nameValue);
protected:
string ID;
string name;
};
worker::worker(string IDValue,string nameValue):ID(IDValue),name(nameValue)
{}
class teacher : public worker
{
public:
teacher(string IDValue,string nameValue,string titleValue,string specialValue);
virtual void display();
protected:
string title;
string special;
};
teacher::teacher(string IDValue,string nameValue,string titleValue,string specialValue):worker(IDValue,nameValue),title(titleValue),special(specialValue)
{}
void teacher::display()
{
cout<<"I am a teacher, my name is "<<name<<", title is "<<title<<", speciality is "<<special<<"."<<endl;
}
class staff : public worker
{
public:
staff(string IDValue, string nameValue, string positionValue);
virtual void display();
protected:
string position;
};
staff::staff(string IDValue, string nameValue, string positionValue):worker(IDValue,nameValue),position(positionValue)
{}
void staff::display()
{
cout<<"I am a staff, my name is "<<name<<", position is "<<position<<"."<<endl;
}
class leader: public worker,public teacher,public staff
{
public:
leader(string IDValue,string nameValue,string titleValue,string specialValue,string positionValue,int num);
virtual void display();
protected:
int workNumber;
};
++++++++++leader::leader(string IDValue,string nameValue,string titleValue,string specialValue,string positionValue,int num):worker(IDValue,nameValue),teacher(titleValue,specialValue),staff(positionValue),workNumber(num)
{}
void leader::display()
{
cout<<"I am a leader, my name is "<<worker.name<<", title is "<<title<<", speciality is "<<special<<", my position is "<<position<<" and there are "<<workNumber<<" worker in my department."<<endl;
}
int main()
{
teacher t1("001","zhangling","instructor","computer");
staff s1("002","wangping","office");
leader l1("003","lisan","professor","computer","headmaster",2000);
t1.display();
s1.display();
l1.display();
return 0;
}
代码如上,在++++
using namespace std;
class worker
{
public:
worker(string IDValue,string nameValue);
protected:
string ID;
string name;
};
worker::worker(string IDValue,string nameValue):ID(IDValue),name(nameValue)
{}
class teacher : public worker
{
public:
teacher(string IDValue,string nameValue,string titleValue,string specialValue);
virtual void display();
protected:
string title;
string special;
};
teacher::teacher(string IDValue,string nameValue,string titleValue,string specialValue):worker(IDValue,nameValue),title(titleValue),special(specialValue)
{}
void teacher::display()
{
cout<<"I am a teacher, my name is "<<name<<", title is "<<title<<", speciality is "<<special<<"."<<endl;
}
class staff : public worker
{
public:
staff(string IDValue, string nameValue, string positionValue);
virtual void display();
protected:
string position;
};
staff::staff(string IDValue, string nameValue, string positionValue):worker(IDValue,nameValue),position(positionValue)
{}
void staff::display()
{
cout<<"I am a staff, my name is "<<name<<", position is "<<position<<"."<<endl;
}
class leader: public worker,public teacher,public staff
{
public:
leader(string IDValue,string nameValue,string titleValue,string specialValue,string positionValue,int num);
virtual void display();
protected:
int workNumber;
};
++++++++++leader::leader(string IDValue,string nameValue,string titleValue,string specialValue,string positionValue,int num):worker(IDValue,nameValue),teacher(titleValue,specialValue),staff(positionValue),workNumber(num)
{}
void leader::display()
{
cout<<"I am a leader, my name is "<<worker.name<<", title is "<<title<<", speciality is "<<special<<", my position is "<<position<<" and there are "<<workNumber<<" worker in my department."<<endl;
}
int main()
{
teacher t1("001","zhangling","instructor","computer");
staff s1("002","wangping","office");
leader l1("003","lisan","professor","computer","headmaster",2000);
t1.display();
s1.display();
l1.display();
return 0;
}
代码如上,在++++