码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 10.9作业


    设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高、体重,再设计一个Stu类,类中包含私有成员:成绩、Per类对象p1,设计这两个类的构造函数、析构函数和拷贝构造函数。
    1. #include
    2. using namespace std;
    3. class Per{
    4. private:
    5. string name;
    6. int age;
    7. double* height;
    8. double* weight;
    9. public:
    10. Per(string name, int age, double height, double weight);
    11. Per(Per &per);
    12. ~Per();
    13. void show();
    14. };
    15. class Stu{
    16. private:
    17. double score;
    18. Per p;
    19. public:
    20. Stu(double score,string name, int age, double height, double weight);
    21. Stu(Stu &stu);
    22. ~Stu();
    23. void show();
    24. };
    25. Per::Per(string name, int age, double height, double weight)
    26. :name(name),age(age),height(new double(height)),weight(new double(weight)){
    27. cout << "Per::有参构造函数" << endl;
    28. }
    29. Per::Per(Per &per)
    30. :name(per.name),age(per.age),height(new double(*per.height)),weight(new double(*per.weight)){
    31. cout << "Per::拷贝构造函数" << endl;
    32. }
    33. Per::~Per(){
    34. delete height;
    35. delete weight;
    36. cout << "Per::析构函数" << endl;
    37. }
    38. void Per::show(){
    39. cout << "name = " << name << "\tage = " << age << "\theight = " << *height << "\tweight = " << *weight;
    40. }
    41. Stu::Stu(double score,string name, int age, double height, double weight)
    42. :score(score),p(name,age,height,weight){
    43. cout << "Stu::有参构造函数" << endl;
    44. }
    45. Stu::Stu(Stu &stu):score(stu.score),p(stu.p){
    46. cout << "Stu::拷贝构造函数" << endl;
    47. }
    48. Stu::~Stu(){
    49. cout << "Stu::析构函数" << endl;
    50. }
    51. void Stu::show(){
    52. p.show();
    53. cout << "\tscore = " << score << endl;
    54. }
    55. int main()
    56. {
    57. Stu s(95.5,"zhang",18,175,120);
    58. s.show();
    59. Stu s1=s;
    60. s1.show();
    61. return 0;
    62. }

  • 相关阅读:
    Git 服务器上的 LFS 下载
    filament沙盒传参数到shader
    想要精通算法和SQL的成长之路 - 验证二叉树的前序序列化
    【机器学习基础】无监督学习(3)——AutoEncoder
    centos7下mongodb安装及开启副本
    MySQL 索引
    2024年蓝牙耳机哪个好?真人实测告诉你如何选购,避免后悔!
    在模块中使用外部依赖的类
    Devops 开发运维高级篇之Jenkins+Docker+SpringCloud微服务持续集成
    uni-app(三):离线打包与插件引用(Android)
  • 原文地址:https://blog.csdn.net/weixin_45904815/article/details/133712758
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号