职工信息系统,继承,输入问题
各位大侠帮我看看这程序怎么修改可以输入名字,而且继承的时候能够显示前面类的show()函数,谢谢了哈:题目:
设计一个基类Person。通过该类保存人员的最基本信息:姓名、年龄和性别。然后使用该类派生出工人类Worker和学生类Student,在其中添加各自的特性,如在Student类中添加如下信息:院系、专业和学号等,在Worker类中添加如下信息:部门和工作等。最后,由于职工大学学员不仅是学生,而且在社会上还是工人,因此需要具备2种属性特征。于是在这个2个派生基类的基础上再次派生出学院类WorSut,它不仅具备Worker的属性,而且具有Student属性。
#include<iostream>
#include<string>
using namespace std;
class student;
class worker;
class worstu;
class person
{
protected:
char name[10];
int age;
char gender[10];
public:
void setname(char n[10]);
void setage(int);
void setgender(char sex[10]);
void show1();
};
void person::setname(char N[10])
{
name[10]=N[10];
}
void person::setage(int A)
{
age=A;
}
void person::setgender(char sex[10])
{
gender[10]=sex[10];
}
void person::show1()
{
cout<<"person name:"<<name<<endl;
cout<<"person age:"<<age<<endl;
cout<<"person gender:"<<gender<<endl;
}
class student:virtual public person
{
protected:
char peparment;
char speciality;
int num;
void Init(char,char,int);
public:
void setpep(char);
void setspe(char);
void setnum(int n);
void show2();
};
void student::setpep(char P)
{
peparment=P;
}
void student::setspe(char S)
{
speciality=S;
}
void student::setnum(int M)
{
num=M;
}
void student::show2()
{
cout<<"the student's information is:"<<endl;
show1();
cout<<"student peparment:"<<peparment<<endl;
cout<<"student speciality:"<<speciality<<endl;
cout<<"student number:"<<num<<endl;
}
class worker:virtual public person
{
protected:
char Deparment;
char Job;
void Init(char,char);
public:
void setDep(char);
void setJob(char);
void show3();
};
void worker::setDep(char D)
{
Deparment=D;
}
void worker::setJob(char J)
{
Job=J;
}
void worker::show3()
{
cout<<"the worker's information is:"<<endl;
show1();
cout<<"worker Deparment:"<<Deparment<<endl;
cout<<"worker Job:"<<Job<<endl;
}
class worstu:public student,public worker
{
public:
void show4();
};
void worstu::show4()
{
cout<<"the worstu information is:"<<endl;
show2();
cout<<"worker Deparment:"<<Deparment<<endl;
cout<<"worker Job:"<<Job<<endl;
}
void main()
{
char i[10],j[10],l,m,o,u;
int k,b;
cout<<"please input personname:";
cin>>i;
cout<<"please input personage:";
cin>>k;
cout<<"please input persongender:";
cin>>j;
person P;
P.setname(i);
P.setage(k);
P.setgender(j);
P.show1();
cout<<"please input studentpeparment:";
cin>>l;
cout<<"please input studentspeciality:";
cin>>m;
cout<<"please input studentnum:";
cin>>b;
student S;
S.setpep(l);
S.setspe(m);
S.setnum(b);
S.show2();
cout<<"please input workerDeparment:";
cin>>o;
cout<<"please input workerJob:";
cin>>u;
worker Y;
Y.setDep(o);
Y.setJob(u);
Y.show3();
worstu Q;
Q.show4();
}