C++作业第四天

#include <iostream>
 
using namespace std;
 
class Per
{
private:
    string name;
    int age;
    int *high;
    double *weight;
public:
    //构造函数
    Per()
    {
        cout << "Per的无参构造" << endl;
    }
    Per(string name,int age,int high,double weight):\
        name(name),age(age),high(new int(high)),weight(new double(weight))
    {
        cout << "Per的有参构造" << endl;
    }
    //析构函数
    ~Per()
    {
        cout << "Per的析构函数" << endl;
        delete (high);
        delete (weight);
    }
    void show()
    {
        cout << name << " " << age << " " << *high << " " << *weight << endl;
    }
};
class Stu
{
private:
    double score;
    Per p1;
public:
    //构造函数
    Stu()
    {
        cout << "Stu的无参构造" << endl;
    }
    Stu(double score,string name,int age,int high,double weight):\
        score(score),p1(name,age,high,weight)
    {
        cout << "Stu的有参构造" << endl;
    }
    //析构函数
    ~Stu()
    {
        cout << "Stu的析构函数" << endl;
    }
    void show()
    {
        cout << score << " ";
        p1.show();
    }
};
int main()
{
    Per p1;
    Per p2("张三",1,190,90.5);
    Stu s1;
    Stu s2(10.2,"李四",2,185,85.3);
    p2.show();
    s2.show();
    return 0;
}

相关推荐

  1. C++作业

    2024-06-12 11:54:03       28 阅读
  2. C语言学习

    2024-06-12 11:54:03       34 阅读

最近更新

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

    2024-06-12 11:54:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-12 11:54:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-06-12 11:54:03       82 阅读
  4. Python语言-面向对象

    2024-06-12 11:54:03       91 阅读

热门阅读

  1. 图论第9天

    2024-06-12 11:54:03       24 阅读
  2. 多进程并发服务器

    2024-06-12 11:54:03       38 阅读
  3. 2024年全国高考作文题目汇总

    2024-06-12 11:54:03       32 阅读
  4. 求最值(C++)

    2024-06-12 11:54:03       26 阅读
  5. 【京存】无惧卡顿

    2024-06-12 11:54:03       24 阅读
  6. 6.11啊啊啊啊啊啊啊

    2024-06-12 11:54:03       29 阅读
  7. NX二次开发消息打印,可用于调试

    2024-06-12 11:54:03       29 阅读
  8. tensorflow安装

    2024-06-12 11:54:03       32 阅读
  9. Web前端图片并排显示的艺术与技巧

    2024-06-12 11:54:03       28 阅读
  10. ubuntu安装deb解决依赖关系错误问题

    2024-06-12 11:54:03       25 阅读
  11. Webapp前端框架模板:探索、实践与创新

    2024-06-12 11:54:03       32 阅读