当前位置: 首页 > news >正文

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;
}

http://www.lryc.cn/news/374406.html

相关文章:

  • 设计模式之工厂方法模式(Factory Method Pattern)
  • API接口设计的18条规范
  • adb简单使用命令
  • 构建 deno/fresh 的 docker 镜像
  • 数据库 | 数据库设计的步骤
  • 改进YOLO系列 | CVPR 2021 | Involution:超越convolution和self-attention的神经网络算子
  • 落地速度与效果之争,通用VS垂直,我的观点和预测。
  • 【Android面试八股文】在Android中,出现ClassNotFound的有可能的原因是什么?
  • 模板引擎与 XSS 防御
  • vue3轮播图怎么做
  • ubuntu中安装docker并换源
  • HTML静态网页成品作业(HTML+CSS)—— 环保主题介绍网页(5个页面)
  • 深入了解RSA加密算法
  • github基础使用
  • Docker使用心得
  • QListWidget 插入 item,item显示自定义界面
  • Python写一个ERP系统和agent智能体协同仓库和订单的案例
  • 【计算机网络】已解决:“‘ping‘ 不是内部或外部命令,也不是可运行的程序或批处理文件”报错
  • Web前端学堂:深入探索前端开发的核心领域
  • Java数据结构与算法(0/1背包问题)
  • LLVM 中 的 pass 及其管理机制
  • 第 5 章 监控系统 | 入门案例 - 虚拟机监控
  • 教资认定报名照片要求小于190kb…
  • 显示类控件——Calendar Widget
  • system与excel族函数区别
  • STM32存储左右互搏 模拟U盘桥接SPI总线FATS读写FLASH W25QXX
  • jrt从量变到质变
  • NLP主流大模型如GPT3/chatGPT/T5/PaLM/LLaMA/GLM的原理和差异有哪些-详细解读
  • 从MySQL到NoSQL:分析传统关系型数据库与NoSQL数据库的协同
  • 三、树和割集