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:总述 最简单的视音频 ...
随机推荐
- BZOJ 1579 道路升级 Dijkstra
思路: 这道题 不能把所有边都建出来 会MLE的!!! oh gosh 其实不建所有的边 用的时候再调就行了-.(也没啥区别) //By SiriusRen #include <queue> ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- C++中explicit关键字作用
explicit是c++中不太常用的一个关键字,其作用是用于修饰构造函数,告诉编译器定义对象时不做隐式转换. 举例说明: include <iostream> include <st ...
- 在不足256M内存的机器上启动RHAS 3时总要停顿10秒的问题
在VM里安装rhas3.0,由于只分配了256M RAM,系统起动总是提示不足256M.我查了一下[root@rhas3 mrtg]# grep -ri "Normal startup wi ...
- How Javascript works (Javascript工作原理) (十一) 渲染引擎及性能优化小技巧
个人总结:读完这篇文章需要20分钟,这篇文章主要讲解了浏览器中引擎的渲染机制. DOMtree ----| |----> RenderTree CSSOMtree ----| ...
- 如何修改Web.Config里面的值
0.先添加 <add key="MAXNUM" value="6" /> 1.读取值 string maxNum = ConfigurationMa ...
- 实现人脸识别性别之路---open CV将图片显示出来
import cv2filename='E:\\tensorflow\\bu.jpg'#图片的地址 # face_cascade=cv2.CascadeClassifier('C:\\anconda3 ...
- centos 7 mongodb4.0 安装配置
1.下载安装 cat <<EOF> /etc/yum.repos.d/mongodb-org-4.0.repo [mongodb-org-4.0]name=MongoDB Repos ...
- jQuery.inArray和splice删除数组元素
不知道数组下标的情况下,删除数组对应元素.实例: var arrays = ['a','b','c','d']; arrays.splice($.inArray('c',arrays),1); ale ...
- CSUOJ 1532 JuQueen
Problem H JuQueen JuQueen is the super computer with the best performance allover Germany. It is on ...