#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;
}
C++day3
最新推荐文章于 2024-09-26 09:13:29 发布
文章展示了C++中类的定义和使用,包括构造函数、析构函数以及多重继承的概念。通过`Student`、`Party`和`Vip`三个类的定义,阐述了如何初始化对象和调用成员方法。`Vip`类是`Student`和`Party`的子类,体现了面向对象的继承特性。
摘要由CSDN通过智能技术生成