Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

简单练习

1.从程序calculator08buggy.cpp开始,修改其中的错误,使之能编译通过。

2.阅读整个计算器程序并添加适当的注释。

3.在注释的过程中,你会发现程序中存在一些错误(我们特意加入了一些不明显的错误让你来查找),这些错误都未在本章中出现过,尝试修正它们。

4.测试:准备一组测试数据,用来测试计算器程序。要注意测试用例的完整性,思考你要通过测试用例查找什么。测试用例应包括负数、0、非常小的数、非常大的数和一些“愚蠢”输入。

5.进行测试,并修改在注释代码过程中没有发现的错误。

6.增加一个预定义名字k,其值为1000。

7.为用户提供平方根函数sqrt(),比如允许用户计算sqrt(2+6.7)。sqrt(x)的值是x的平方根,例如sqrt(9)的值为3。使用标准库函数sqrt()完成平方根的计算,这个函数包含在头文件std_lib_facilities.h中。记得更新程序代码注释以及文法。

8.捕获求负数的平方根的异常,并给出适当的错误信息。

9.增加幂函数pow(x,i),例如pow(2.5,3)表示2.5*2.5*2.5,要求i为整数,可使用与%运算符相同的方法处理。

10.将“声明关键字”let改为#。

11.将“退出关键字”quit改为exit,与let的处理一样,我们需要定义一个表示“退出”的字符串,参见7.8.2节。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252