博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Accelerated C++:通过演示样例进行编程实践——练习解答(第9章)
阅读量:6227 次
发布时间:2019-06-21

本文共 2200 字,大约阅读时间需要 7 分钟。

我的Github地址:

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。

转载地址:http://patna.baihongyu.com/

你可能感兴趣的文章
linux光驱挂到本地目录
查看>>
jQuery Ajax实例 ($.ajax_$.post_$.get)
查看>>
第一课JAVA开发环境配置
查看>>
linux的NFS详细配置方法
查看>>
Eclipse中Spring插件的安装及使用
查看>>
git 出现错误 Could not resolve host: github.com 或者 gitlab.com 或者gerrit相关( 自有服务 )...
查看>>
eclipse中启动项目报内存溢出问题通过修改配置解决
查看>>
垃圾桶丁
查看>>
Windows环境下python2.7安装mysql-python
查看>>
InnoDB的三个关键特性
查看>>
请教一个问题:关于 webrtc 通信的问题
查看>>
SDE里修改要素的已有字段的长度
查看>>
openStack高可用性和灾备方案
查看>>
svn完整搭建
查看>>
programData
查看>>
python正则表达式二[转]
查看>>
Easyui datagrid
查看>>
win11.2.0.4lsnrctl status hang
查看>>
黑盒测试实践作业进度报告(周四)
查看>>
json和jsonp
查看>>