学生类和教师类的设计

Problem Description

一个教学系统至少有学生和教师两种类型的人员,假设教师的数据有教师编号、姓名、年龄、性别、职称和系别,
学生的数据有学号、姓名、年龄、性别、班级和语文、数学、英语三门课程的成绩。
现编程完成学生和教师档案数据的输入和显示。
要求如下:
设计三个类Person、Teacher、Student,Person是Teacher和Student的基类,
具有此二类共有的数据成员编号、姓名、年龄、性别,并具有输入和显示这些数据的成员函数;
Teacher类继承了Person类的功能,并增加职称和系别等数据成员和进行输入和显示的成员函数。
Student类继承了Person类的功能,并增加班级和语文、数学、英语三门课程的成绩等数据成员
及进行输入和显示的成员函数。 
//你的代码将被嵌入在这里
int main() {
    Teacher t1, t2("T002", "张华", 33, "男", "讲师", "计算机系");
    Student s1, s2("S002", "李丽", 19, "女", "0309202", 90, 92, 98);
    t1.inputTeacher();
    s1.inputStudent();

    t1.printTeacher();
    t2.printTeacher();
    s1.printStudent();
    s2.printStudent();

    Person p = t1;
    p.printPerson();

    return 0;
}

Sample Input

T001 陈军 40 女 教授 电气工程
S001 向辉 28 男 0309201 99 98 97

Sample Output

num:T001
name:陈军
age:40
sex:女
title:教授
dep:电气工程
--------------------
num:T002
name:张华
age:33
sex:男
title:讲师
dep:计算机系
--------------------
num:S001
name:向辉
age:28
sex:男
classes:0309201
chinese:99
math:98
english:97
--------------------
num:S002
name:李丽
age:19
sex:女
classes:0309202
chinese:90
math:92
english:98
--------------------
num:T001
name:陈军
age:40
sex:女
#include<iostream>
#include<string>
using namespace std;
class Person
{
protected:
    string num;//编号
    string name;//姓名
    int age;//年龄
    string sex;//性别
public:
    Person(string nu = "", string na = "", int ag = 0, string se = "");
     
     
    void inputPerson()
    {
        cin >> num >> name >> age >> sex;
    }
    void printPerson()
    {
        cout << "num:" << num << endl;
        cout << "name:" << name <<
            endl;
        cout << "age:" << age << endl;
        cout<< "sex:" << sex << endl;
         
    }
}; Person::Person(string nu,string na, int ae, string se)
{
    num = nu;
    name = na;
    age = ae;
    sex = se;
}
class Teacher:public Person
{
protected:
    string title, dep;
public:
    Teacher(){}
        Teacher(string num,string name, int age, string sex, string title,string dep):Person(num,name,age,sex),title(title),dep(dep){}
         
        void inputTeacher()
        {
             
            cin>>num>>name>>age>>sex>>title>>dep;
        }
        void printTeacher()
        {
            cout << "num:" << num << endl;
            cout << "name:" << name <<
                endl;
            cout << "age:" << age << endl;
            cout << "sex:" << sex << endl;
            cout << "title:" << title << endl;
            cout<< "dep:" << dep << endl;
            cout << "--------------------" << endl;
        }
};
class Student :public Person
{
protected:
    string classes;
    double math, chinese, english;
public:
    Student(){}
    Student(string num,string name,int age,string sex,string classes,double chinese,double math,double english):Person(num,name,age,sex),classes(classes),chinese(chinese),math(math),english(english){}
    void inputStudent()
    {
        cin >> num >> name >> age >> sex;
        cin >> classes;
        cin >> chinese;
        cin >> math;
         
        cin >> english;
    }
    void printStudent()
    {
        cout << "num:" << num << endl;
        cout << "name:" << name << endl;
        cout << "age:" << age << endl;
        cout << "sex:" << sex << endl;
        cout << "classes:" << classes << endl;
        cout<<"chinese:"<<chinese << endl;
        cout << "math:" << math << endl;
        cout<<"english:"<<english << endl;
        cout << "--------------------" << endl;
    }
};

  • 4
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

最爱阿依哇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值