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.编写一个使用while循环语句的程序,每次循环输入两个int数据并输出它们,当输入'|'后程序结束。

2.修改程序,输出“the smaller value is:”后接着输出较小的整数,输出“the larger value is:”后接着输出较大的整数。

3.改进程序:当两个整数相等时,输出“the numbers are equal”。

4.改变程序:输入的数据改为double型而不是int型。

5.改变程序:依次输出较大和较小的数。如果两个数的差小于1.0/100的话,再输出“the numbers are almost equal”。

6.改变循环体程序:每次循环只输入一个double型数据,并用两个变量记录到目前为止的最小数和最大数。每次循环输出当前输入的数据,如果这个数据是到目前为止最小或最大的数,在其后分别输出“the smallest so far”和“the largest so far”。

7.为每个double型数据增加单位,例如数据可以是10cm、2.5in、5ft或3.33m。程序可以接受四种计量单位cm、m、in和ft,假定转换系数是1m==100cm,1in==2.54cm,1ft==12in。将单位读入一个字符串。考虑12m(数字和单位之间有空格)等价于12m(没有空格)。

8.改进程序使之拒绝没有单位或单位非法的数据,例如y、yard、meter、km和gallons等。

9.除了记录到目前为止最大和最小的数据外,还记录到目前为止的数据累加和以及数据个数。循环结束后,输出最小、最大、数据个数以及累加和。注意,因为计算累加和必须使用同一计量单位,所以需要事先决定使用哪个计量单位,例如米。 ...

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