C++-编写一个学生和教师数据输入和显示程序 学生数据有编号、姓名、班号和成绩; 教师数据有编号、姓名、职称和部门。 要求将编号、姓名的输入和显示设计成一个类person,并作为学生数据操作类

#include<iostream>
#include<string> // 使用 <string> 替代之前的头文件

using std::cout;
using std::endl;

class person
{
public:
    // 使用 const char* 而不是 char*
    person(const char* a, const char* b)
    {
        name = a;
        num = b;
    }

    void Getterab()
    {
        cout << "name:" << name << "  " << "num:" << num << "  ";
    }

private:
    const char* name; // 使用 const char* 而不是 char*
    const char* num;  // 使用 const char* 而不是 char*
};

class student : public person
{
private:
    const char* number;
    double score;

public:
    student(const char* a, const char* b, const char* c, double d) : person(a, b)
    {
        number = c;
        score = d;
    }

    void show()
    {
        Getterab();
        cout << "number:" << number << "  " << "score:" << score << "\n";
    }
};

class teacher : public person
{
private:
    const char* section;
    const char* job;

public:
    teacher(const char* a, const char* b, const char* c, const char* d) : person(a, b)
    {
        section = c;
        job = d;
    }

    void show1()
    {
        Getterab();
        cout << "section:" << section << "  " << "job:" << job << endl;
    }
};

int main()
{
    student a("张三", "24", "1", 82);
    a.show();
    teacher b("李四", "01", "网络系", "老师");
    b.show1();
    return 0;
}
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值