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.编写一个C++程序,将英里转换成公里。你的程序应该有一个合理的提示,要求用户输入一个表示英里的数字。提示:1英里等于1.609公里。

3.编写一个程序,不做其他的任何事情,只声明一系列合法与不合法的变量名(例如int double=0;),这样你可以看到编译器的反应。

4.编写一个程序,提示用户输入两个整型值。将这些值保存在int变量val1和val2中。编写你的程序求这两个值中的最小值、最大值、和、差、乘积和比率,并且将结果输出给用户。

5.修改上个程序,让用户输入浮点数值并将它们保存在double变量中。比较你选择的多种输入在两个程序的输出。这些结果是否相同?它们是否应该相同?区别是什么?

6.编写一个程序,提示用户输入三个整型值,然后按数值大小顺序用逗号隔开的方式输出这些值。因此,如果用户输入值为1046,输出值应为4,6,10。如果有两个值相同,那么将它们按序一起输出。因此,输入454将会输出4,4,5。

7.做习题6,但是输入3个字符串。因此,如果用户输入“Steinbeck”、“Hemingway”和“Fitzgerald”,输出将是“Fitzgerald,Hemingway,Steinbeck”。

8.编写一个程序,测试一个整型值是奇数还是偶数。确保你的输出是清楚和完整的。换句话说,不要只是输出“yes”或“no”。你的输出应该是独立的,例如“The value4is an even number。”提示:阅读3.4节中的余数(模)操作。

9.编写一个程序,将拼写的数字(例如“zero”和“two”)转换成数值(例如0和2)。当用户输入一个拼写的数字,程序将打印出对应的数字。针对数值0、1、2、3和4完成这个操作,如果用户输入没有对应的值(例如“stupid ...

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