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

【C++ Primer Plus习题】10.2

问题:

这里是引用
在这里插入图片描述

解答:
main.cpp

#include <iostream>
#include "Person.h"
using namespace std;int main()
{Person one;Person two("Smythecraft");Person three("Dimwiddy", "Sam");one.FormalShow();one.Show();cout << endl;two.FormalShow();two.Show();cout << endl;three.FormalShow();three.Show();return 0;
}

Person.h

#pragma once
#include <iostream>using namespace std;class Person
{
private:static const int LIMIT = 25;string lname;//姓char fname[LIMIT];//名
public:Person() { lname = ""; fname[0] = '\0'; }Person(const string& ln, const char* fn = "Heyyou");void Show()const;void FormalShow()const;
};

Person.cpp

#include "Person.h"Person::Person(const string& ln, const char* fn )
{strcpy_s(this->fname, fn);this->lname = ln;
}
void Person::Show() const
{cout << "名:" << this->fname << endl;cout << "姓:" << this->lname << endl;
}
void Person::FormalShow() const
{cout << "姓:" << this->lname << endl;cout << "名:" << this->fname << endl;
}

运行结果:
在这里插入图片描述

考查点:

  • 类和对象

2024年9月3日20:16:27


http://www.mrgr.cn/news/19127.html

相关文章:

  • 我克隆了我自己,数字生命有什么意义?
  • 数据结构:顺序表的应用--仓库货物管理信息管理系统
  • 9.3总结
  • pikachu文件包含漏洞靶场通关攻略
  • B站视频自动驾驶master(2)
  • P01-Java何谓数组
  • 【MA35D1】buildroot 编译使用经验
  • flink窗口分组数据错乱
  • 笔记整理—uboot番外(2)find_cmd函数
  • Linux系统入门:加密与解密原理、数据安全及系统服务访问控制策略分析
  • @EnableAutoConfiguration注解使用和原理
  • glsl着色器学习(七)
  • malloc/free 和 new/delete的区别
  • 遇到bug怎么分析,这篇文章值得一看
  • Java学习|Java基础知识
  • C++11中的constexpr
  • 【网络】HTTPS协议
  • Python 从入门到实战6(二维列表)
  • 数据结构----链表
  • 实现一个简单的车贷计算小程序(含代码)