C++--DAY3

思维导图

设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高、体重,再设计一个Stu类,类中包含私有成员:成绩、Per类对象p1,设计这两个类的构造函数、析构函数。
 

#include <iostream>

using namespace std;
class Person
{
    string name;
    int age;
    int *high;
    double *weight;
public:
    Person():name("路人甲"),age(18),high(new int(175)),weight(new double(45.00))
    {
        cout << "person的无参构造" << endl;
    }
    Person(string name,int age,int high,double weight):name(name),age(age),high(new int(high)),weight(new double(weight))
    {
        cout << "person的有参构造" << endl;
    }
    ~Person()
    {
        delete high;
        delete weight;
        cout << "person的析构函数" << endl;
    }
    void show()
    {
        cout << " 姓名:" << name << " 年龄:" << age << " 身高:" << *high << " 体重:" << *weight << endl;
    }
};
class Student
{
    float score;
    Person p1;
public:
    Student():score(60.00),p1()
    {
        cout << "students的无参构造" << endl;
    }
    Student(string name,int age,int high,double weight,float score):score(score),p1(name,age,high,weight)
    {
        cout << "students的有参构造" << endl;
    }
    ~Student()
    {
        p1.~Person();
        cout << "student的析构函数" << endl;
    }
    void show()
    {
        cout << "成绩:" << score
                ;
        p1.show();

    }
};

int main()
{
    Person p2;
    p2.show();
    Student s1("浮生",22,185,53.03,86.5);
    s1.show();
    return 0;
}

相关推荐

  1. <span style='color:red;'>c</span>++ <span style='color:red;'>day</span><span style='color:red;'>3</span>

    c++ day3

    2024-06-06 00:02:06      56 阅读
  2. c++day3

    2024-06-06 00:02:06       50 阅读
  3. <span style='color:red;'>C</span>++<span style='color:red;'>Day</span><span style='color:red;'>3</span>

    C++Day3

    2024-06-06 00:02:06      57 阅读
  4. <span style='color:red;'>C</span>++ <span style='color:red;'>day</span><span style='color:red;'>3</span>

    C++ day3

    2024-06-06 00:02:06      60 阅读
  5. <span style='color:red;'>day</span><span style='color:red;'>3</span>-<span style='color:red;'>C</span>++

    day3-C++

    2024-06-06 00:02:06      30 阅读
  6. <span style='color:red;'>c</span>++<span style='color:red;'>day</span><span style='color:red;'>3</span>

    c++day3

    2024-06-06 00:02:06      38 阅读
  7. <span style='color:red;'>C</span>++ <span style='color:red;'>day</span><span style='color:red;'>3</span>

    C++ day3

    2024-06-06 00:02:06      34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-06 00:02:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-06 00:02:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-06 00:02:06       82 阅读
  4. Python语言-面向对象

    2024-06-06 00:02:06       91 阅读

热门阅读

  1. 直播带货行业的瓶颈来了吗?

    2024-06-06 00:02:06       24 阅读
  2. 旋转之后截取图像

    2024-06-06 00:02:06       29 阅读
  3. 服务器硬件基础知识

    2024-06-06 00:02:06       30 阅读
  4. 【Redis】本地锁和分布式锁的区别

    2024-06-06 00:02:06       27 阅读
  5. Kafka 请求处理揭秘:从入门到精通

    2024-06-06 00:02:06       27 阅读
  6. 如何发现并解决 Redis 热点 Key 问题

    2024-06-06 00:02:06       35 阅读
  7. 字幕转换: vtt转为srt

    2024-06-06 00:02:06       29 阅读
  8. 都可以写好后端接口

    2024-06-06 00:02:06       18 阅读
  9. 服务器环境搭建

    2024-06-06 00:02:06       30 阅读
  10. Sass详解

    2024-06-06 00:02:06       34 阅读
  11. React@16.x(19)事件的处理

    2024-06-06 00:02:06       30 阅读