C++继承与派生习题

这是一个关于C++编程的实例,展示了如何通过继承和派生创建一个`professor`类,该类从`teacher`类派生,并添加了生日属性。程序包括输入和输出成员函数,允许用户输入教师的个人信息和生日,然后进行更新和显示。在主函数中,演示了如何使用自定义的输入和输出操作符重载来交互地获取和输出`professor`对象的信息。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class teacher
{
protected:
    int sum;
    string name;
    char sex;
public:
    void input_A()
    {
        cout<<"Please input the teacher's sum,name and sex:";
        cin>>sum;
        cin>>name;
        cin>>sex;
    }
    void output_A()
    {
        cout<<"sum:"<<sum<<"name:"<<name<<"sex:"<<sex<<endl;
    }
};
class birthday
{
public:
    int year,month,day;
        void input_B()
        {
            cout<<"Please input the teacher's birthday:(year,month,day):";
            cin>>year;
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值