完整题干:
编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班级和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师类数据操作类teacher的基类。
个人答案:
#include<iostream>
#include<string>
using namespace std;
class Person //声明基类
{
public:
Person(string name1, int number1)//基类构造函数
{
name = name1;
number = number1;
}
void display()//输出基类数据成员
{
cout << "姓名:" << name << endl;
cout << "编号:" << number << endl;
}
protected://保护部分
string name;
int number;
};
class Student :public Person //声明公用派生类student,即学生的相关数据
{
public:
Student(string name1, int number1, int class_number1, int score1) ://派生类构造函数
Person(name1, number1)
{
class_number = class_number1;//对派生类新增的数据成员初始化
score = score1;
}
void show()//输出学生的所有相关数据
{
display();//输出姓名和编号
cout << &#