首页 > 编程语言 >2024.9.4C++作业

2024.9.4C++作业

时间:2024-09-04 19:52:01浏览次数:6  
标签:std coutzhiwei name 2024.9 age 作业 C++ Human include

#include <iostream>
#include <string>
using namespace std;
class Human
{
    public:
    Human()
    {
        name = "Unknown";
        age = 0;
    }
    Human(string n, int a)
    {
        name = n;
        age = a;
    }
    ~Human()
    {
        cout<<"析构函数被调用"<<endl;
    }
    void show()
    {
        cout<<"姓名:"<<name<<" 年龄:"<<age<<endl;
    }


private:
    string name;
    int age;
};
class Student:public Human
{
    public:
        Student()
        {
            score = 0;
        }
        Student(string name,int age,int a):Human(name,age)
        {
            score = a;
        }
        ~Student()
        {
            cout<<"析构函数被调用"<<endl;
        }
        void show()
        {
            cout<<"score="<<score<<endl;
            Human::show();
            
        }

    private:
        int score;
};
class Party:public Human
{
    public:
        Party()
        {
            zuzhi = "Unknown";
            huodong = "Unknown";
        }
        Party(string n, string a)
        {
            zuzhi = n;
            huodong = a;
        }
        ~Party()
        {
            cout<<"析构函数被调用"<<endl;
        }
        void show()
        {
            cout<<"组织:"<<zuzhi<<" 举办活动:"<<huodong<<endl;
        }

    private:
        string zuzhi;
        string huodong;
        
};

class Student_cadre:public Student,public Party
{
    public:
        Student_cadre()
        {
            zhiwei = "Unknown";
        }
        Student_cadre(string name, int age, int score, string zuzhi, string huodong, string zhiwei):Student(name,age,score),Party(zuzhi,huodong)
        {
            this->zhiwei = zhiwei;
        }
        ~Student_cadre()
        {
            cout<<"析构函数被调用"<<endl;
        }
        void show()
        {
            cout<<"职位:"<<zhiwei<<endl;
            Student::show();
            Party::show();
        }

    private:
        string zhiwei;
};
int main()
{
    Student_cadre s1("张三", 20, 90, "学生会", "篮球比赛", "学生会长");
    s1.show();
    return 0;
   
}

标签:std,coutzhiwei,name,2024.9,age,作业,C++,Human,include
From: https://blog.csdn.net/qq_63490254/article/details/141902465

相关文章

  • 2024.9.3C++
    自行实现Mystring类#include<iostream>#include<cstring>usingnamespacestd;classmystring{public:mystring(){len=0;str=nullptr;}mystring(constchar*s){len=strlen(s);str=ne......
  • 2024.9.2C++作业
    自行实现一个Mystring类#include<iostream>#include<cstring>usingnamespacestd;classmystring{public:mystring(){len=0;str=nullptr;}mystring(constchar*s){len=strlen(s);str=n......
  • C++基础之杂项
    目录思维导图:学习内容:1. Lambda表达式1.1基本概念1.2定义格式1.3常用情况二、异常处理2.1什么是异常处理2.2何时使用异常处理2.3异常处理的格式2.4异常实例2.5构造和析构中的异常 2.6系统提供异常类 三、C++中文件操作3.1文件流对象的介绍3.2关......
  • Codeforces Round 971 (Div. 4) ABCD题详细题解(C++,Python)
    前言:    本文为CodeforcesRound971(Div.4)ABCD题的题解,包含C++,Python语言描述,觉得有帮助或者写的不错可以点个赞    比赛打了没一半突然unrated了就不是很想继续写了,早起写个题解    (之前的div3也没复盘,哎真菜)目录题A:题目大意和解题......
  • AtCoder Beginner Contest 369 题ABCD详细题解--包含解题思路和两种语言(C++,Python)
    前言:    本文为AtCoderBeginnerContest369题ABCD详细题解,包括题目大意,详细的解题思路和两种语言描述,觉的有帮助或者写的不错可以点个赞几天前的比赛拖的有点久了比赛题目连接:Tasks-AtCoderBeginnerContest369目录题A:题目大意和解题思路:代码(C++):......
  • c++学习7、函数探幽
    #include<iostream>#include<string>usingnamespacestd;structcrdit{ stringname; intage; stringaddress;};structjob{ charname[40]; doublesalary; intfloor;};inlinedoublesquare(doublex){returnx*x;}//定义了一个内联函数square—......
  • 多目标应用:四种多目标优化算法(NSOOA、NSPSO、NSDBO、NSCOA)求解柔性作业车间调度问题(F
    一、柔性作业车间调度问题柔性作业车间调度问题(FlexibleJobSchedulingProblem,FJSP)的描述如下:n个工件{J,J......
  • C++和OpenGL实现3D游戏编程【连载7】——文字和汉字的显示
    1、本节实现的内容上一节我们讨论了纹理在二维平面内不规则图形贴图的相关基础操作,本节我们开始了解游戏里文字以及汉字的显示方法。本节课我们将从基本的ASCII字符显示,拓展到中文字符的显示,最后再讲到纹理字符的显示,并对各种文字显示方法的优缺点和使用场景进行分析,这节课......
  • 初次部分使用c++语言无意发现个数组元素查找的代码
    includeusingnamespacestd;//定义结构体structMyArray{intarr[100];//数组,假设最大长度为100intsize;//数组当前元素数量};//输入函数,修改数组内容voidscanf(MyArray&myArray){for(inti=0;i<myArray.size;i++){cin>>myArray.arr[i];//键盘......
  • 南沙信奥赛C++陈老师解一本通题:1341:【例题】一笔画问题
    ​ 题目描述】如果一个图存在一笔画,则一笔画的路径叫做欧拉路,如果最后又回到起点,那这个路径叫做欧拉回路。根据一笔画的两个定理,如果寻找欧拉回路,对任意一个点执行深度优先遍历;找欧拉路,则对一个奇点执行dfs,时间复杂度为O(m+n),m为边数,n是点数。【输入】第一行n,m,有n个点,m条......