《C++程序设计原理与实践》 复习题答案,可作为C++基础知识复习(持续更新中)

本文是《C++程序设计原理与实践》的复习资料,涵盖计算机、对象、类型、值、计算、错误处理等多个章节的重点内容,如软件的重要性、类型安全、表达式与语句的区别、错误分类、向量与数组的操作等,旨在帮助读者巩固C++的基础知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

第一章 计算机、人与程序设计

第三章 对象、类型和值

第四章 计算


第一章 计算机、人与程序设计

1. What is software? 软件是运行在计算机上的程序的集合
2. Why is software important?
3. Where is software important?
4. What could go wrong if some software fails? List some examples.
5. Where does software play an important role? List some examples.
6. What are some jobs related to software development? List some.
7. What’s the difference between computer science and programming?
8. Where in the design, construction, and use of a ship is software used?
9. What is a server farm?
10. What kinds of queries do you ask online? List some.
11. What are some uses of software in science? List some.
12. What are some uses of software in medicine? List some.
13. What are some uses of software in entertainment? List some.
14. What general properties do we expect from good software?
15. What does a software developer look like?
16. What are the stages of software development? 分析、设计、编程、测试
17. Why can software development be difficult? List some reasons.
18. What are some uses of software that make your life easier?
19. What are some uses of software that make your life more difficult?

 

第三章 对象、类型和值

1. What is meant by the term prompt? 提示符:简单的输出一个信息,prompts the user to take an action
2. Which operator do you use to read into a variable? >>
3. If you want the user to input an integer value into your program for a variable named number, what are two lines of
code you could write to ask the user to do it and to input the value into your program?
4. What is \n called and what purpose does it serve? 换行
5. What terminates input into a string? 空白符所终止,包括空格、换行、tab字符
6. What terminates input into an integer? 做数值的读入操作时,通过非数值字符来结束输入
7. How would you write
cout << "Hello, ";
cout << first_name;
cout << "!\n";
as a single line of code?
8. What is an object?  An object is a region of memory with a type that specifies what kind of information can be placed in it
9. What is a literal? Literals represent values of various types
10. What kinds of literals are there? Interger, Floating-point, Boolean, Character, String, Pointer
11. What is a variable?  A variable is a named object.
12. What are typical sizes for a char, an int, and a double? 1字节、2字节、8字节
13. What measures do we use for the size of small entities in memory, such as ints and strings?
14. What is the difference between = and ==? 赋值和等于
15. What is a definition?  A definition is a declaration that sets aside memory for an object.
16. What is an initialization and how does it differ from an assignment?  Initialization (giving a variable its initial value)初始化时变量总是空的;赋值则必须将旧的值清空
17. What is string concatenation and how do you make it work in C++? 将两个字符串连接起来,s1+s2
18. Which of the following are legal names in C++? If a name is not legal, why not?

This_little_pig This_1_is fine 2_For_1_special 数字开头
latest thing 没有下划线 the_$12_method 有符号 _this_is_ok 不是字母开头
MiniMineMine没有下划线 number correct?有符号


19. Give five examples of legal names that you shouldn’t use because they are likely to cause confusion. nameS,  names, f00, foo, f1, fl
20. What are some good rules for choosing names? 名字必须以字母开始,并且只能有字母、数字和下划线;选择有特定含义的名字(有助于人们理解你的程序的名字);使用下划线来区分单词;不要使用很长的名字;使用首字母大写来定义自己的类型;避免使用容易错误、误读或混淆的名字
21. What is type safety and why is it important? 每个对象在定义时被分配一个类型,如果使用的对象符合它们规定的类型,那么它们是类型安全的
22. Why can conversion from double to int be a bad thing? 因为从double到int转换会截断(总是去掉小数点后的尾数),而不是使用常用的四舍五入
23. Define a rule to help decide if a conversion from one type to another is safe or unsafe. 一个值转换为另一个类型的值,这个值是否等于原始的值

 

第四章 计算

1. What is a computation? 基于输入生成输出的过程
2. What do we mean by inputs and outputs to a computation? Give examples. 输入(参数):信息进入计算机;输出(结果):信息离开计算机
3. What are the three requirements a programmer should keep in mind when expressing computations? 正确、简单、高效
4. What does an expression do? 表达式通过一系列操作来计算一个数值量(value)
5. What is the difference between a statement and an expression, as described in this chapter?
6. What is an lvalue? List the operators that require an lvalue. Why do these operators, and not the others, require an
lvalue? 左值:赋值符号左边的,表示对象
7. What is a constant expression? 表达式与整数组合 
8. What is a literal? 
9. What is a symbolic constant and why do we use them? 符号常量:表示那些初始化后值就不再改变的数值量。常量对于维护程序的可读性具有重要作用
10. What is a magic constant? Give examples. 不能直接识别的字面常量
11. What are some operators that we can use for integers and floating-point values?
12. What operators can be used on integers but not on floating-point numbers?
13. What are some operators that can be used for strings? 
14. When would a programmer prefer a switch-statement to an if-statement? 基于数值与多个常量比较的选择
15. What are some common problems with switch-statements? switch语句括号中的值必须是整型、字符型或枚举型;case语句中的值必须是常量表达式;不能再两个case语句中使用相同的数值;允许

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值