c++题目,高手进!!

来源:百度知道 编辑:UC知道 时间:2024/05/25 09:11:30
编写一个学生和教师数据输入和显示程序,学生数据要求有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名的输入和显示设计成一个基类person,类student和类teacher都继承类person,学生数据中的班号和成绩的输入和显示在student类中实现,教师数据中的职称和部门的输入和显示在teacher类中实现。最后在主函数中进行该类的测试。
下面给出了基类person的主要成员:
(1) 私有成员:
 int no; 编号
 char name[10]; 姓名
(2) 公有成员:
 void input(); 编号和姓名的输入
 void display(); 编号和姓名的显示
编程题,要完整代码!!

#include<iostream>
using namespace std;
class Person{
private:
int no;
char name[10];
public:
void input(){
cin>>no>>name;
}
void display(){
cout<<no<<" "<<name<<" ";
}
};
class Student:public Person{
private:
int no_class;
double score;
public:
void input_s(){
input();
cin>>no_class>>score;
}
void display_s(){
display();
cout<<no_class<<" "<<score<<endl;
}
};
class Teacher:public Person{
private:
char title[10];
char department[10];
public:
void input_t(){
input();
cin>>title>>department;
}
void display_t(){
display();
cout<<title<<" "<<department<<endl;
}
};
void main(){
T