c++作业-day5


整理思维导图


Person类,私有成员(姓名,年龄,縞,体重),公有成员方法(有参构造函数、析构函数、show函数)
Stu类,继承派生自Person类,私有成员(成绩,班级),公有成员方法(有参构造函数、析构函数、show函数), 实例化一个Stu
对象并调用show函数

 

#include <iostream>

using namespace std;
class person
{
    string name;
    int age;
    int high;
    int weight;
public:
    person(string name,int age,int high,int weight):name(name),age(age),high(high),weight(weight)
    {
        cout<<"有参构造函数"<<endl;
    }
    ~person()
    {
        cout<<"析构函数"<<endl;
    }
    void show()
    {
        cout<<"age="<<age<<endl;
        cout<<"high="<<high<<endl;
        cout<<"weight="<<weight<<endl;
        cout<<"name="<<name<<endl;
        cout<<"-----------"<<endl;
    }
};
class stu:public person
{
    int score;
    string c;
public:
    stu(string name,int age,int high,int weight,int score,string c):person(name,age,high,weight),score(score),c(c)
    {
        cout<<"stu有参构造"<<endl;
    }
    ~stu()
    {
        cout<<"stu析构函数"<<endl;
    }
    void show()
    {
        cout<<"class="<<c<<endl;
        cout<<"score="<<score<<endl;
        cout<<"-----------"<<endl;
    }
};
int main()
{
    stu stu1("zs",12,180,80,90,"xx");
    stu1.person::show();
    stu1.show();
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值