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.如果你尚未做本章“试一试”中的练习,请先完成。

2.在程序中增加对{}的处理,令其与()作用一致,这样,{(4+5)*6}/(3+4)就是一个合法的表达式。

3.在程序中增加对阶乘运算符(用‘!’表示)的处理,例如:表达式7!表示7*6*

5*4*3*2*1。阶乘的优先级高于*和/,也就是说,7*8!表示7*(8!)而不是(7*8)!。通过修改文法来描述优先级更高的运算符,为了与数学中阶乘的定义统一,我们规定0!等于1。提示:我们的计算器程序处理的是double型数,但阶乘只对整数有定义,所以对x!,先将x赋给一个int型变量,再计算该int型变量的阶乘。

4.定义包含一个字符串和一个值两个成员的类Name_value,使用vector<Name_value>替代两个vector重做第4章的习题19。

5.将the加到6.4.1节中的“英语”文法中,以便能描述“The birds fly but the fish swim”这样的语句。

6.根据6.4.1节中给出的“英语”文法,编写程序判断一个句子是否符合英语语法。假设每个句子都以句号(.)结束,句号的两边有空格。例如,“birds fly but the fish swim.”是一个合法的句子,但“birds fly but the fish swim”(缺少句号)和“birds fly but the fish swim.”(句号之前没有空格)都不是正确的句子。对输入的每个句子,程序能够输出“OK”或者“not OK.”。提示:不需使用单词,直接使用>>来读入字符串即可。

7.为位逻辑表达式编写一个文法。位逻辑表达式与算术表达式是非常相像的,只是前者使用的是逻辑运算符!(非)、~(补)、&(与)、|(或)和^(异或),每个运算符都对其整数操作数的每一位进行计算。其中,!与~是前缀一元运算符,^运算的优先级高于|运算(正如*运算优先级高于+运算一样),因此x|y^z表示x|(y^z)而不是(x|y)^z;&运算的优先级高于^运算,因此x^y&z表示x^(y&z)。 ...

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