[求助]程序有问题 请达人们指点下小弟 (继承的问题)
/*编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、
职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数
据操作类teacher的基类。
*/
#include<iostream.h>
#include<string.h>
class Student; //学生类
class Teacher; //教师类
class Person //人类
{
private:
int id;
char name[20];
public:
Person(int x,char *p)
{
id=x;
strcpy(name,p);
}
void show(Student s)
{
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "班号:" << s.getclassid() << endl;
cout << "成绩:" << s.getscore() << endl;
}
void show(Teacher t) //show函数的重载
{
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "职称:" << t.getzhicheng() << endl;
cout << "部门:" << t.getbumen() << endl;
}
};
class Student:public Person
{
private:
int classid;
double score;
public:
void setclassid(int x) //设置私有属性班级号
{
classid=x;
}
void setscore(double y) //设置私有属性成绩
{
score=y;
}
int getclassid()
{
return classid;
}
double getscore()
{
return score;
}
};
class Teacher:public Person
{
private:
char zhicheng[10]; //职称
char bumen[10]; //部门
public:
void setzhicheng(char *p) //设置私有属性职称
{
strcpy(zhicheng,p);
}
void setbumen(char *p) //设置私有属性部门
{
strcpy(bumen,p);
}
char getzhicheng()
{
return zhicheng;
}
char getbumen()
{
return bumen;
}
};
void main()
{
Person s1(1,"小强");
Student p1;
p1.setclassid(15);
p1.setscore(90.8);
s1.show(p1);
}