打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
派生类

#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
    Student(int n,string nam)
    {
        num=n;
        name=nam;
    }

    void display()
    {
        cout<<"num:"<<num<<endl;
        cout<<"name:"<<name<<endl;

    }

protected:
    int num;
    string name;
};

class Student1:public Student
{
public :
    Student1(int n,string nam,int a):Student(n,nam)
    {
        age=a;
    }
    void show()
    {
        display();
        cout<<"age:"<<age<<endl;
    }

private:
    int age;
};

class Student2:public Student1
{
public:
    Student2(int n,string nam,int a,int s):Student1(n,nam,a)
    {
        score=s;
    }
    void show_all()
    {
        show();
        cout<<"score:"<<score<<endl;
    }

private:
    int score;
};

int main(){
    Student2 stud(10010,"Li",17,89);
    stud.show_all();
    return 0;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C++派生类的构造函数
20、继承和派生(一)
C++虚基类详解
第四题
【C 】结构体讲解
c++ 继承 向下造型与向下造型 隐式转换 显示转换
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服