Accelerated C++:通过演示样例进行编程实践——练习解答(第9章)
我的Github地址:https://github.com/lanbeilyj/Accerlerated-C-plus-plus
9-0. Compile, execute, and test the programs in this chapter.
Ans:见Github。
9-1. Reimplement the Student_info
class so that it calculates the finalgrade
when reading the student's record, and stores that grade in the object. Reimplement thegrade
function to use this precomputed value.
Ans:见Github。
9-2. If we define the name
function as a plain, nonconst
member function, what other functions in our system must change and why?
Ans:我们只须要改动函数 compare()的參数类型就可以:将原先的bool compare(const Student_info& x,const Student_info& y)改为
bool compare(Student_info x,Student_info y)
Tips:const对象不能够调用const成员函数函数。
为什么又把 Student_info& 改成了Student_info x?
由于sort(students.begin(),students.end(),compare),函数中传递给compare是一个const对象,由于不能用一个const对象来初始化一个非const引用,故须要改动为传值形式。
9-3. Our grade
function was written to throw an exception if a user tried to calculate a grade for aStudent_info
object whose values had not yet been read. Users who care are expected to catch this exception. Write a program
that triggers the exception but does not catch it. Write a program that catches the exception.
Ans:见Github。
9-4. Rewrite your program from the previous exercise to use thevalid
function, thereby avoiding the exception altogether.
Ans:见Github。
9-5. Write a class and associated functions to generate grades for students who take the course for pass/fail credit. Assume that only the midterm and final grades matter, and that a student passes with an average exam score greater than 60. The
report should list the students in alphabetical order, and indicate P or F as the grade.
Ans:见Github。
9-6. Rewrite the grading program for the pass/fail students so that the report shows all the students who passed, followed by all the students who failed.
Ans:见Github。
9-7. The read_hw
function §4.1.3/57 solves a general problem (reading a sequence of values into avector
) even though its name suggests that it should be part of the implementation ofStudent_info
. Of course,
we could change its name—but suppose, instead, that you wanted to integrate it with the rest of theStudent_info
code, in order to clarify that it was not intended for public access despite its apparent generality? How would you do so?
Ans:见Github。
Accelerated C++:通过演示样例进行编程实践——练习解答(第9章)的更多相关文章
- 最简单的视音频播放演示样例3:Direct3D播放YUV,RGB(通过Surface)
===================================================== 最简单的视音频播放演示样例系列文章列表: 最简单的视音频播放演示样例1:总述 最简单的视音频 ...
- 【UNIX网络编程(三)】TCP客户/server程序演示样例
上一节给出了TCP网络编程的函数.这一节使用那些基本函数编写一个完毕的TCP客户/server程序演示样例. 该样例运行的过程例如以下: 1.客户从标准输入读入一行文本,并写给server. 2.se ...
- C编程规范, 演示样例代码。
/*************************************************************** *Copyright (c) 2014,TianYuan *All r ...
- MVC模式编程演示样例-登录验证(静态)
好,上篇博客分享了本人总结的JSP-Servlet-JavaBean三层架构编程模式的实现思想和基本流程,接下来给大家分享一个MVC编程模式的实现演示样例-登录验证的过程,这里我仍然用的是静态的验证u ...
- 构造Scala开发环境并创建ApiDemos演示样例项目
从2011年開始写Android ApiDemos 以来.Android的版本号也更新了非常多,眼下的版本号已经是4.04. ApiDemos中的样例也添加了不少,有必要更新Android ApiDe ...
- android listview综合使用演示样例_结合数据库操作和listitem单击长按等事件处理
本演示样例说明: 1.自己定义listview条目样式,自己定义listview显示列数的多少,灵活与数据库中字段绑定. 2.实现对DB的增删改查,而且操作后listview自己主动刷新. 3.响应用 ...
- 百度地图 Android SDK - 检索功能使用的简单演示样例
百度地图 SDK 不仅为广大开发人员提供了炫酷的地图展示效果.丰富的覆盖物图层,更为广大开发人员提供了多种 LBS 检索的能力. 通过这些接口,开发人员能够轻松的訪问百度的 LBS 数据,丰富自己的移 ...
- [hadoop系列]Pig的安装和简单演示样例
inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish ).(来源:http://blog.csdn.net/inkfish) Pig是Yaho ...
- 最简单的视音频播放演示样例5:OpenGL播放RGB/YUV
===================================================== 最简单的视音频播放演示样例系列文章列表: 最简单的视音频播放演示样例1:总述 最简单的视音频 ...
随机推荐
- VS 2015支持C语言和C++程序
先要安装C++的相关支持控件! 然后就可以使用VS编写C++或者C程序了. 默认支持的是C++,将后缀名改为C就是支持C了. 学习数据结构算法之类的,就可以通过VS来学习了. 安装 新建C++项目 C ...
- Android的矩阵(一):ColorMatrix
最近的学习过程中看到关于android色彩矩阵的内容,以前看到这部分内容,基本都是跳过的,没有认真细读. 自己给自己找的借口是: 1,大一学的矩阵内容早就忘的干干净净了,当时学的时候就很烦人,所以现在 ...
- 深入Vue的响应式原理
工作的过程中,有时候会有数据改变但是视图没有更新的问题,作者在vue的官方文档中有提到这个问题,我来总结一下 1.vue的每个组件实例都有对象的watcher实例对象,它会在组件渲染的过程中把属性记录 ...
- css3 实现动画效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- word中添加Mathtype公式行间距改变问题
转载链接:http://blog.sciencenet.cn/home.php?mod=space&uid=471807&do=blog&id=616838 最近碰到在word ...
- web.config添加identity impersonate="true"导致拒绝访问
例:<identity impersonate="tr" userName="AD\name" password="word"/> ...
- 关于【搭建LAMP环境时,php测试页面打不开】解决
关于[搭建LAMP环境时,php测试页面打不开]解决 〇.我的测试页面是: http://172.30.124.10/index.php 用火狐打不开,如下图. 一.httpd已经启动了(system ...
- OpenJDK源码研究笔记(十五):吐槽JDK中的10个富有争议的设计
前14篇文章,分享了JDK中值得学习和借鉴的编码和设计方法. 每个硬币都是有两面的.Every coin has two sides. 当然,JDK中也有很多值得改进或者说富有争议的设计. 本篇,就来 ...
- 详解如何在vue项目中引入饿了么elementUI组件
在开发的过程之中,我们也经常会使用到很多组件库:vue 常用ui组件库:https://blog.csdn.net/qq_36538012/article/details/82146649 今天具体说 ...
- Linux发行版centos, ubuntu等
公司装的是centos,centos其实就是无支持版的redhat. redhat是一个服务器的操作系统它的稳定性是比较高的,同时提供在线管理服务,服务器故障预警等,当然前提是要购买昂贵的服务. Su ...