c++第三次作业(2024.9.4)

#include <iostream>

using namespace std;

class Human{
	private:
		int age;
		string name;
	public:
		Human()
		{
			cout<<"Human无参构造!\n";
			age = 0;
			name = "";
		}
		Human(const int a,const string b):age(a),name(b)
		{
			cout<<"Human有参构造!\n";
		}
		~Human(){
			cout<<"Human析构函数!\n";
		}
		void show(){
			cout<<"age="<<age<<"\nname="<<name<<endl;
		}
};

class Student : public Human{
	private:
		float score;
	public:
		Student()
		{
			cout<<"Student无参构造!\n";
			score = 0;
		}
		Student(const int a,const string b,const float c):Human(a,b),score(c)
		{
			cout<<"Student有参构造!\n";
		}
		~Student()
		{
			cout<<"Student析构函数!\n";
		}
		void show(){
			Human::show();
			cout<<"score="<<score<<endl;
		}
};

class Party : public Human{
	private:
		string activity;
		string organization;
	public:
		Party()
		{
			cout<<"Party无参构造!\n";
			activity="";
			organization="";
		}
		Party(const int a,const string b,const string c,const string d):Human(a,b),activity(c),organization(d)
		{
			cout<<"Party有参构造!\n";
		}
		~Party()
		{
			cout<<"Party析构函数!\n";
		}
		void show(){
			Human::show();
			cout<<"activity="<<activity<<endl;
			cout<<"organization="<<organization<<endl;
		}
};

class Cadre : public Party,public Student{
	private:
		string position;
	public:
		Cadre()
		  {
			cout<<"Cadre无参构造!\n";
			position="";
		}
		Cadre(const int a,const string b,const float c,const string d,const string e,const string f)
			:Student(a,b,c),Party(a,b,d,e),position(f)
		{
			cout<<"Cadre有参构造!\n";
		}
		~Cadre()
		{
			cout<<"Cadre析构函数!\n";
		}
		void show(){
			Student::show();
			Party::show();
			cout<<"position="<<position<<endl;
		}
};


int main(int argc, const char *argv[])
{
	Cadre c;
	c.show();
	cout<<endl;
	Cadre c2(18,"张三",96.3,"活动","组织","岗位");
	c2.show();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值