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.修改第7章的计算器程序,将输入流作为一个显式参数(如8.5.8节所示)。并为Token_stream设计接受istream&参数的构造函数,这样,当我们解决了如何使用自己的输入流时(比如关联到一个文件),就可以将之用于计算器程序。提示:不要试图拷贝istream对象。

2.编写一个函数print(),将一个整型vector输出到cout。此函数接受两个参数:一个字符串(用于“标记”输出)和一个vector。

3.创建一个斐波那契数的vector,并用习题2中的函数输出这个vector。编写函数fibonacci(x,y,v,n)来创建vector,其中x、y是int型,v是vector<int>类型空vector,n是要放入v的元素数目,将v[0]和v[1]分别设置为x和y。斐波那契数列是这样一个整型序列,其中每个元素都是前面两个元素之和。例如,以1和2开始,可以得到斐波那契数列1,2,3,5,8,13,21,…你设计的fibonacci()函数应该以参数x和y作为开始,生成如前的斐波那契数列。

4.计算机中int型对象能保存的整数的值是有上限的。使用fibonacci()函数求这个上限的近似值。

5.编写两个函数,反转一个vector<int>类型vector中的元素顺序。例如,将1、3、5、7、9转换为9、7、5、3、1。第一个反转函数生成一个新vector,其中元素为原vector的逆序,而原vector内容不变。另一个反转函数不使用任何其他vector,直接在原vector中反转元素顺序(提示:swap)。

6.对vector<string>类型vector,重做习题5。

7.读入5个名字,存入一个vector<string>型vector name,然后提示用户输入这些人的年龄,存入一个vector<double>型vector ...

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