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

作业11.30

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

#include <iostream>

using namespace std;
class Per
{
private:
    string name;
    int age;
    double weight;
    double height;
public:
    Per()
    {
//        cout << "Per::无参构造函数" << endl;
    }
    Per(string name,int age,double weight,double height):name(name),age(age),weight(weight),height(height)
    {
//        cout << "Per::有参构造函数" << endl;
    }
    ~Per()
    {
//        cout << "Stu::析构函数" << endl;
    }
    Per(const Per &other):name(other.name),age(other.age),weight(other.weight),height(other.height)
    {
//        cout << "Stu::拷贝函数" << endl;
    }
    void show()
    {
        cout << "Per name=" << name << endl;
        cout << "Per age=" << age << endl;
        cout << "Per weight=" << weight << endl;
        cout << "Per height=" << height << endl;
    }
};
class Stu
{
private:
    double score;
    Per p1;
public:
    Stu()
    {
//        cout << "Stu::无参构造函数" << endl;
    }
    Stu(double score,string name,int age,double weight,double height):score(score),p1(name,age,weight,height)
    {
//        cout << "Stu::有参构造函数" << endl;
    }
    ~Stu()
    {
//        cout << "Stu::析构函数" << endl;
    }
    Stu(const Stu &other):score(other.score)
    {
//        cout << "Stu::拷贝函数" << endl;
    }
    void show()
    {
        cout << "Stu score=" << score << endl;
        p1.show();
    }
};

int main()
{
    Per p1;
    Per p2("张三",28,56,176);
    Per p3(p2);
    p3.show();
    Stu s1;
    Stu s2(98,"李四",27,55,176);
    Stu s3=s2;
    s2.show();
    return 0;
}

2.思维导图


http://www.kler.cn/a/152274.html

相关文章:

  • 什么是灯塔工厂?灯塔工厂的作用?
  • Java 的第二十章:多线程
  • SpringBoot 整合Redis
  • MediaPipe - 小记
  • asla四大开源组件应用示例(alsa-lib、alsa-utils、alsa-tools、alsa-plugins)
  • 智能井盖位移报警器效果一览,感知井盖异常
  • vscode Markdown 预览样式美化多方案推荐
  • uc_09_创建新进程 exec() system()
  • C++基础——文件操作
  • 蓝桥杯-02-蓝桥杯Java组考点与14届真题
  • 【开源视频联动物联网平台】帧率、码率和分辨率
  • 微信小程序 slider 翻转最大和最小值
  • 使用Java将properties转为yaml,保证顺序、实测无BUG版本
  • @Openssh【rpm软件包7.x升级9.0版本(Centos7.9)】
  • 免杀原理(php)
  • 旋转框(obb)目标检测计算iou的方法
  • 微服务实战系列之EhCache
  • JavaScript添加快捷键、取消浏览器默认的快捷操作、js查看键盘按钮keycode值
  • 中国毫米波雷达产业分析3——毫米波雷达市场分析(四、五、六)
  • 数字图像处理(实践篇)十四 图像金字塔