C++day3

文章展示了C++中类的定义和使用,包括构造函数、析构函数以及多重继承的概念。通过`Student`、`Party`和`Vip`三个类的定义,阐述了如何初始化对象和调用成员方法。`Vip`类是`Student`和`Party`的子类,体现了面向对象的继承特性。
摘要由CSDN通过智能技术生成
#include <iostream>

using namespace std;

class Student
{
private:
    string name;
    int age;
    int score;
public:
    Student()
    {
        cout <<"Student::Parameterless constructio" << endl;
    }
    Student(string n,int a,int s):name(n),age(a),score(s)
    {
        cout << "Student::Parametric construction" << endl;
    };
    ~Student()
    {
        cout << "Student::gouxihanshu " << endl;
    }
    Student show()
    {
        cout << "name=" << name << endl;
        cout << "age=" << age << endl;
        cout << "score=" << score << endl;
    }
};

class Party
{
private:
    string activities;
    string organization;
public:
    Party()
    {
        cout <<"Party::Parameterless constructio" << endl;
    }
    Party(string a1,string o):activities(a1),organization(o)
    {
        cout << "Party:: Parametric construction" << endl;
    }
    ~Party()
    {
        cout << "Party::xigouhanshu" << endl;
    }
    void show()
    {
        cout << "activities=" << activities << endl;
        cout << "organization=" << organization << endl;
    }
};


class Vip:public Student,public Party
{
private:
    string job;
public:
    Vip()
    {
        cout << "Vip::Parameterless constructio" << endl;
    }
    Vip(string n,int a,int s,string a1,string o,string j):Student(n,a,s),Party(a1,o),job(j)
    {
        cout << "Vip:: Parametric construction" << endl;
    }
    ~Vip()
    {
        cout << "Vip::xigouhanshu" << endl;
    }
    void show()
    {
        Student::show();
        Party::show();
        cout << "job=" << job << endl;
    }

};

int main()
{
    Vip v("clw",21,66,"College of youth","Chinese Communist Youth League","leader");
    v.show();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值