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

C++_day4

思维导图

代码

#include <iostream>//设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高
//、体重,再设计一个Stu类,类中包含私有成员:成绩、Per类对象
//p1,设计这两个类的构造函数、析构函数和拷贝构造函数、拷贝赋值函数。
using namespace std;class Per
{
private:string name;int age;double *heigh,*weigh;
public:
//    Per()
//    {
//        cout << "Per::无参构造函数" << endl;
//    }Per(string name="--",int age=0,double heigh=0.0,double weigh=0.0):name(name),age(age),heigh(new double(heigh)),weigh(new double(weigh))   //构造函数{cout << "Per::有参构造函数" << endl;}Per(const Per &other):name(other.name),age(other.age),heigh(new double(*(other.heigh))),weigh(new double(*(other.weigh))){cout << "Per::拷贝构造函数" << endl;}Per &operator=(const Per &other){if(this != &other){name=other.name;age=other.age;heigh=other.heigh;weigh=other.weigh;}cout << "Per::拷贝赋值函数" << endl;return *this;}~Per(){delete heigh;delete weigh;cout << "Per::析构函数" << endl;}void show(){cout << name << " " << age << " " << *heigh << " " << * weigh << " " ;}
};class Stu
{
private:Per p1;double score;
public:Stu(){cout << "Stu::无参构造函数" << endl;}Stu(string name,int age,double heigh,double weigh,double score):p1(name,age,weigh,heigh),score(score){cout << "Stu::有参构造函数" << endl;}Stu(const Stu &other):p1(other.p1),score(other.score){cout << "Stu::拷贝构造函数" << endl;}Stu &operator=(const Stu &other){if(this!=&other){p1=other.p1;score=other.score;}cout << "Stu::拷贝赋值函数" << endl;return *this;}~Stu(){cout << "Stu::析构函数" << endl;}void show(){p1.show();cout<< score <<endl;}
};int main()
{Per p1;p1.show();cout << endl;Per p3("李四",19,199,67);p3.show();cout << endl << "========================" << endl;Stu s3;Stu s1("张三",18,189,56,99);s1.show();cout << "========================" << endl;Per p2(p1);p2.show();cout << endl << "========================" << endl;Stu s2(s1);s2.show();cout << "========================" << endl;p1=p3;p1.show();cout << endl << "========================" << endl;s3=s1;s1.show();cout << "========================" << endl;return 0;
}

http://www.dtcms.com/a/423221.html

相关文章:

  • 多解法详解与边界处理——力扣7.整数反转
  • 网站开发 python网站员工风采
  • ptyhon 基础语法学习(对比php)
  • 热点新闻事件及评论杭州seo网站推广
  • FITC-Fucoidan用于生物材料表面修饰、药物载体构建、纳米颗粒功能化和分子追踪研究
  • 【LeetCode】52. N 皇后 II
  • web网页开发,在线%推荐算法学院培养计划,图书推荐,基于Python,FlaskWeb,用户和物品推荐MySql
  • 半导体制造业中如何检测薄膜的厚度?
  • Redis为什么快
  • 3D 和 4D 世界建模:综述(下)
  • VPS服务器时区设置与优化,提升系统时间准确性
  • 爆肝整理,性能测试-双十一等大促活动稳定性保障分析,一篇通透...
  • 网络维护网站足球比赛直播平台app免费
  • 新天力科技IPO进行时:技术引领未来,创新驱动发展
  • 从0到1构建高并发电商返利APP:基于Spring Cloud Alibaba的分布式架构设计与核心模块拆解
  • 土地质量地球化学调查与评价系统:科技赋能土地智慧治理
  • 网站开发一定得用html吗软件开发是用什么软件
  • Spring Boot 核心启动机制与配置原理剖析
  • 精读C++20设计模式——结构型设计模式:外观模式
  • How Can Objects Help Video-Language Understanding?论文阅读
  • 《AI智能体实战开发教程(从0到企业级项目落地)》全网上线|CSDN B站同步首发
  • Python学习历程——组织结构(包含for、if、while等等)
  • cronet从编译到修改之: 支持IP直连
  • 美团网站建设规划书俄罗斯搜索引擎入口 yandex
  • Java微服务知识点详细总结
  • 做网站需要哪些工程师网络优化岗位详细介绍
  • 南昌网站全新开发小型教育网站的开发建设开题报告
  • .NET开发中3秒判断该用 IEnumerable 还是 IQueryable
  • 【Java EE进阶 --- SpringBoot】Mybatis操作数据库(基础)
  • 【Docker + DockerCompose】安装步骤+演示