非城勿扰,不要不是高手就来,分,我可以再加,只要你解决的好。以下是代码。
#includeiostream.h
#includestring
classTeacher
{
private:
intnum;
charname[20];
charsex[2];
charpos[20];
public:
voiddisplay();
friendvoidchangeT(Teacher
//使用此函数主要为了可以改变Teacher类中的成员。
};
voidTeacher::display()
{
coutthis-num;
for(inti=0;i20;i)
coutthis-name;
for(intj=0;j2;j)
coutthis-sex[j];
for(intk=0;k20;k)
coutthis-pos[k];
}
voidchangeT(Teacher
strcpy(t.name,b);
strcpy(t.sex,c);
strcpy(t.pos,\"Teacher\");
}
classStudent
{
private:
intnum;
charname[20];
charsex[2];
charpos[20];
public:
voidinput();
friendTeacherchangeS(Student
//使用此函数主要为了转换Student类对象成为Teacher类的对象
};
voidStudent::input()
{
cinthis-num;
for(inti=0;i20;i)
cinthis-name;
for(intj=0;j2;j)
cinthis-sex[j];
for(intk=0;k20;k)
cinthis-pos[k];
}
TeacherchangeS(Student
inta;
charb[20];
charc[2];
a=x.num;
strcpy(b,x.name);
strcpy(c,x.sex);
changeT(d,a,b,c);
returnd;
}
intmain()
{
Studentstu;
Teachertea;
cout\"Pleaseinputthestudent\'sinformation\"endl;
tea=changeS(stu);
cout\"Hereisthestudenttoteacher\'smassage!\"endl;
tea.display();
return0;
}
|