目录

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

第三章 对象、类型和值

第四章 计算


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

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_pigThis_1_is fine2_For_1_special 数字开头
latest thing 没有下划线the_$12_method 有符号_this_is_ok 不是字母开头
MiniMineMine没有下划线numbercorrect?有符号


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语句中使用相同的数值;允许多个case语句使用相同的符合语句;每个case语句末尾加上break
16. What is the function of each part of the header line in a for-loop, and in what sequence are they executed? 初始化、循环条件、增量操作;
17. When should the for-loop be used and when should the while-loop be used?
18. How do you print the numeric value of a char? char c; cout<<int(c);
19. Describe what the line char foo(int x) means in a function definition. 名为foo的函数,有一个int型参数(名为x),返回值是char型
20. When should you define a separate function for part of a program? List reasons.
21. What can you do to an int that you cannot do to a string? 
22. What can you do to a string that you cannot do to an int? 
23. What is the index of the third element of a vector? vector<int> v(6); 向量名
24. How do you write a for-loop that prints every element of a vector? 
25. What does vector<char> alphabet(26); do?
26. Describe what push_back() does to a vector. 将一个新元素添加到向量中,该元素成为向量的最后一个元素
27. What do vector’s member functions begin(), end(), and size() do? 向量开始的位置、向量结束的位置、获得向量的大小
28. What makes vector so popular/useful?
29. How do you sort the elements of a vector? v.sort();
 

第五章 错误

1. Name four major types of errors and briefly define each one. Compile-time errors:由编译器发现的错误,包括语法错误、类型错误。链接时错误:当链接器试图将对象文件链接为可执行文件时发现的错误。运行时错误:程序运行时发现的错误,包括硬件和操作系统的错误、库检测出的错误、用户代码检测出的错误。逻辑错误:由程序员发现的会导致不正确结果的错误。
2. What kinds of errors can we ignore in student programs?
3. What guarantees should every completed project offer? 对所有合法输入应输出正确结果;对所有非法出入应输出错误信息;不需要关心硬件故障;不需要关心系统软件故障
4. List three approaches we can take to eliminate errors in programs and produce acceptable software. 精心组织软件结构以减少错误;通过调试和测试,消除大部分程序错误;确定余下的错误是不重要的。
5. Why do we hate debugging? 因为是编程中最乏味、最费时间的工作
6. What is a syntax error? Give five examples. 不符合C++语言的语法规范
7. What is a type error? Give five examples. 你给变量和函数声明的类型和你赋予参数的值的类型或者表达式的类型是否匹配type errors; that is, it will report mismatches between the types you declared (or forgot to declare) for your variables, functions, etc. and the types of values or expressions you assign to them, pass as function arguments
8. What is a linker error? Give three examples. 程序中每一个函数在所有翻译单元中的声明类型必须严格一致,使用头文件来保证这一点;程序中每个函数只能定义一次。如果上述两条规则的任意一条被违反,链接器将报错。
9. What is a logic error? Give three examples. 程序能运行,但是要么没有输出要么输出结果是错误的。具体原因可能是你所理解的程序逻辑是错误的
10. List four potential sources of program errors discussed in the text. 缺少规划;不完备的程序;意外的参数;意外的输入;意外的状态;逻辑错误
11. How do you know if a result is plausible? What techniques do you have to answer such questions? 将结果与正确的结果对比。通过估计大概计算一个合理的答案
12. Compare and contrast having the caller of a function handle a run-time error vs. the called function’s handling the runtime error.
13. Why is using exceptions a better idea than returning an “error value”?
14. How do you test if an input operation succeeded? 通过测试cin,可以确定最后一个输入操作是否成功  if(cin){}
15. Describe the process of how exceptions are thrown and caught. 当函数发现一个自己不能处理的错误,它不是正常返回,而是抛出异常来表示错误的发生。任何一个直接或间接的函数调用者都可以捕捉到这一异常,可以用try语句来处理异常:把所有要处理的异常情况罗列在catch语句后。如果出现一个没有任何调用函数处理的异常,程序终止运行。
16. Why, with a vector called v, is v[v.size()] a range error? What would be the result of calling this? 因为它超出了vector的存储空间范围。下标操作将抛出一个名为out_of_range的异常
17. Define pre-condition and post-condition; give an example (that is not the area() function from this chapter), preferably
a computation that requires a loop. 前置条件:函数对于它的参数的要求;后置条件:a condition that must hold upon exit from a piece of code, such as a function or a loop.
18. When would you not test a pre-condition? 没人会使用错误参数;做前置条件检查会使我的程序变慢;检查工作太复杂
19. When would you not test a post-condition?
20. What are the steps in debugging a program?  程序编译通过、正确链接、完成我们希望它做的工作
21. Why does commenting help when debugging? 注释的内容是代码说不清楚的部分
22. How does testing differ from debugging? 测试时系统的查找错误的方法(测试用例)

 

第七章 完成一个程序

1. What is the purpose of working on the program after the first version works? Give a list of reasons. 使程序更易于用户使用,更方便开发者维护
2. Why does 1+2; q typed into the calculator not quit after it receives an error?
3. Why did we choose to make a constant character called number? 因为数字不容易记住,很容易造成人为错误
4. We split main() into two separate functions. What does the new function do and why did we split main()?
5. Why do we split code into multiple functions? State principles.
6. What is the purpose of commenting and how should it be done? 用于补充代码本身没有表达清楚的思想
7. What does narrow_cast do? 缩小转换
8. What is the use of symbolic constants?
9. Why do we care about code layout?
10. How do we handle % (remainder) of floating-point numbers?  将浮点数转换为整型数
11. What does is_declared() do and how does it work?
12. The input representation for let is more than one character. How is it accepted as a single token in the modified code?
13. What are the rules for what names can and cannot be in the calculator program?
14. Why is it a good idea to build a program incrementally?
15. When do you start to test?
16. When do you retest?
17. How do you decide what should be a separate function?
18. How do you choose names for variables and functions? List possible reasons.
19. Why do you add comments?
20. What should be in comments and what should not?
21. When do we consider a program finished?
 

第八章 函数相关技术细节

1. What is the difference between a declaration and a definition? 定义会分配内存空间,而非定义声明仅仅告诉你使用一个名字,它只是一个借口,不会分配内存空间
2. How do we syntactically distinguish between a function declaration and a function definition? 有函数体的是定义
3. How do we syntactically distinguish between a variable declaration and a variable definition? 变量声明extern int a;
4. Why can’t you use the functions in the calculator program from Chapter 6 without declaring them first?
5. Is int a; a definition or just a declaration? 定义
6. Why is it a good idea to initialize variables as they are declared? 避免引入错误
7. What can a function declaration consist of? 返回类型、函数名、形参表
8. What good does indentation do?
9. What are header files used for? 统一管理声明
10. What is the scope of a declaration? 声明点到作用域结束的区间
11. What kinds of scope are there? Give an example of each. 全局作用域、名字空间作用域、类作用域:类内的程序区域、局部作用域:{}、语句作用域:for语句内
12. What is the difference between a class scope and local scope?
13. Why should a programmer minimize the number of global variables?
14. What is the difference between pass-by-value and pass-by-reference? 传值是将参数的值复制一份交给函数,而传引用是将地址交给函数
15. What is the difference between pass-by-reference and pass-by-const-reference? 传常量引用,不能修改传来的对象(参数);而传引用则函数可以其参数
16. What is a swap()? 交换两个数字
17. Would you ever define a function with a vector<double>-by-value parameter? 不会。传值只适合传递非常小的对象,比如一个或两个整型数、双精度数等
18. Give an example of undefined order of evaluation. Why can undefined order of evaluation be a problem? v[i] = i++;
19. What do x&&y and x||y, respectively, mean?
20. Which of the following is standard-conforming C++: functions within functions, functions within classes, classes within
classes, classes within functions?
21. What goes into an activation record? 记录函数调用者所需要的信息
22. What is a call stack and why do we need one? 调用栈:一种只在一端增长和缩减的数据结构。因为需要它来记录函数调用
23. What is the purpose of a namespace? 无需定义一个类型就能将类、函数、数据和类型组织成一个可识别的命名实体
24. How does a namespace differ from a class?
 

第九章 类相关的技术细节

1. What are the two parts of a class, as described in the chapter? 接口和实现
2. What is the difference between the interface and the implementation in a class? 接口用public:标识,实现用private:标识
3. What are the limitations and problems of the original Date struct that is created in the chapter?
4. Why is a constructor used for the Date type instead of an init_day() function? 使用构造函数,忘记初始化时,编译器会捕获这个错误
5. What is an invariant? Give examples. 不变式:判定有效值的规则。
6. When should functions be put in the class definition, and when should they be defined outside the class? Why?当需要从小函数的内联中获得性能提升时,将函数放在类定义内。
7. When should operator overloading be used in a program? Give a list of operators that you might want to overload (each
with a reason). 重载运算符能大大改善代码。+,-,*,/
8. Why should the public interface to a class be as small as possible? 因为小的接口易于学习和记忆,而且实现者也不会为不必要的和很少使用的功能浪费大量时间。当错误发生时,我们只需要检查很少的函数来定位错误
9. What does adding const to a member function do? 表示这个成员函数可以在一个常量对象上调用,保证成员函数不会修改对象
10. Why are “helper functions” best placed outside the class definition? 辅助函数:接受一个类对象作为其参数,为这个类做辅助工作
 

第十章 输入/输出流

1. When dealing with input and output, how is the variety of devices dealt with in most modern computers? I/O设备的处理细节放在设备的驱动程序中,通过一个I/O库访问设备驱动程序
2. What, fundamentally, does an istream do? 将字符序列转化为不同类型的值,从某处获取字符
3. What, fundamentally, does an ostream do? 将不同类型的值转换成字符序列,将这些字符序列发送到“某处”
4. What, fundamentally, is a file? 一个从0开始编号的字节序列
5. What is a file format? 格式:一组规则来确定其中字节的含义。知道一个文件的格式,就能弄清文件中比特流的意思
6. Name four different types of devices that can require I/O for a program.
7. What are the four steps for reading a file? 知道文件名、打开文件、读出字符、关闭文件
8. What are the four steps for writing a file? 知道文件名、打开文件、写入对象、关闭文件
9. Name and define the four stream states. good()操作成功 、eof()到达文件尾、 fail()发生意外情况 、bad()发生严重意外
10. Discuss how the following input problems can be resolved:
a. The user typing an out-of-range value 抛出一个异常,让其他代码来处理这个错误
b. Getting no value (end of file) 抛出一个异常,让其他代码来处理这个错误
c. The user typing something of the wrong type 在负责输入的代码中处理错误
11. In what way is input usually harder than output?
12. In what way is output usually harder than input?
13. Why do we (often) want to separate input and output from computation?
14. What are the two most common uses of the istream member function clear()? 调用clear()后,流的状态变为good();
15. What are the usual function declarations for << and >> for a user-defined type X? ostream& operator<<(ostream& os,const X& x)   istream& operator<<(istream& is,const X& x)

 

第十一章 定制输入/输出

1. Why is I/O tricky for a programmer?
2. What does the notation << hex do? 八进制输出
3. What are hexadecimal numbers used for in computer science? Why? 输出硬件相关的信息,因为一个十六进制数字精确地表示了4位二进制值。因此8个十六进制数则表示4字节的值(通常是一个字或一个寄存器的大小)
4. Name some of the options you may want to implement for formatting integer output. 取消前缀、显示前缀
5. What is a manipulator? 操纵符:改变流的行为的关键字
6. What is the prefix for decimal? For octal? For hexadecimal? 十进制、八进制、十六进制
7. What is the default output format for floating-point values? ;  defaultfloat is the default format (also known as the general format)默认为6位数字长度
8. What is a field? 一个值输出所占用的宽度
9. Explain what setprecision() and setw() do. 设置精度  设置域宽:精确指定一个整数或一个字符串输出占用多少个位置
10. What is the purpose of file open modes?
11. Which of the following manipulators does not “stick”: hex, scientific, setprecision(), showbase, setw? 域宽不是持久的
12. What is the difference between character I/O and binary I/O? 二进制I/O是对象在内存中对应的字节序列简单的复制到文件
13. Give an example of when it would probably be beneficial to use a binary file instead of a text file. 要读写的文件的制作者选择了二进制格式
14. Give two examples where a stringstream can be useful. 将真实I/O和数据处理分离
15. What is a file position? 在文件中定位到指定位置
16. What happens if you position a file position beyond the end of file?
17. When would you prefer line-oriented input to type-specific input? 面向行的输入:默认的空白符不符合我们的要求。
18. What does isalnum(c) do? c是字母或十进制数字吗

 

第十四章 设计图形类

1. What is an application domain?
2. What are ideals for naming? 不同的操作应该有不同的名字
3. What can we name?
4. What services does a Shape offer? 表示可显示在window中的对象
5. How does an abstract class differ from a class that is not abstract? 抽象类只能做其他类的基类
6. How can you make a class abstract? 构造函数为protected的,目的是不能直接创建这个类的对象。还有就是类中有纯虚函数virtual void f()=0,有纯虚函数就不能创建这个类的对象
7. What is controlled by access control? 控制访问的权限
8. What good can it do to make a data member private? 保护类的描述不会被设计者以不可预见的方式更改,从而使我们能用更少的精力写出更好的类
9. What is a virtual function and how does it differ from a non-virtual function? 在基类中定义一个函数,在派生类中有一个类型和名称完成一样的函数,当用户调用函数时,实际上调用的是派生类中的函数
10. What is a base class?
11. What makes a class derived?
12. What do we mean by object layout? 数据成员在内存中的存储。内存布局:堆、栈、自由存储区、全局/静态存储区、常量存储区
13. What can you do to make a class easier to test?
14. What is an inheritance diagram? 类之间的关系
15. What is the difference between a protected member and a private one? 受保护的,它的名字只能被其所属类机器派生类成员使用。私有的,它的名字只能被其所属类的成员使用
16. What members of a class can be accessed from a class derived from it?
17. How does a pure virtual function differ from other virtual functions? virtual void f()=0;
18. Why would you make a member function virtual? 实现多态
19. Why would you make a virtual member function pure? 带纯虚函数的类的目标是提供纯粹的接口,即它们倾向于不包含任何数据成员
20. What does overriding mean? 定义一个和基类中虚函数的名称和类型都相同的函数,以使派生类的函数代替基类中的版本被放入vtbl中的技术称为覆盖
21. How does interface inheritance differ from implementation inheritance? 
22. What is object-oriented programming? 继承、运行时多态、封装的使用
 

第十七章 向量和自由空间

1. Why do we need data structures with varying numbers of elements?
2. What four kinds of storage do we have for a typical program?  堆、栈、自由存储区、全局/静态存储区、常量存储区
3. What is the free store? What other name is commonly used for it? What operators support it? 自由存储(堆,但是网上有自由存储不是堆的说法)是C++中通过new与delete动态分配和释放对象的抽象概念
4. What is a dereference operator and why do we need one? 解引用:查看指针指向对象的值
5. What is an address? How are memory addresses manipulated in C++? 地址:一个指出在内存中位置的数字
6. What information about a pointed-to object does a pointer have? What useful information does it lack?
7. What can a pointer point to? 
8. What is a leak?
9. What is a resource?   something that is acquired and must later be released, such as a file handle, a lock, or memory.
10. How can we initialize a pointer?  int* p1 = new int; int* p1 = new int(1); int* p1 = new int[5];
11. What is a null pointer? When do we need to use one? 当0被赋给一个指针时,0(nullptr)被称为空指针。通过检测指针是否为0,来判断指针是否有效(是否指向什么东西);我们需要一个指针有时指向一个对象,有时不指向时,需要空指针。
12. When do we need a pointer (instead of a reference or a named object)?
13. What is a destructor? When do we want one? 析构函数:确认一个对象是否被正确销毁。
14. When do we want a virtual destructor? 如果有一个带有虚函数功能的类,则它需要一个虚的析构函数
15. How are destructors for members called?
16. What is a cast? When do we need to use one? 类型转换
17. How do we access a member of a class through a pointer? 对于一个对象指针,所有类支持通过->操作符来访问成员
18. What is a doubly-linked list? 可以在一个链接上找到前驱和后继
19. What is this and when do we need to use it? this:指向用户调用成员函数所用对象的指针(myclss my; my里面的this就是指向my的指针)。 只要是在访问成员,就可以省略指向当前对象的指针this,只有当需要引用整个对象时,我们才需要显示使用this

 

第十八章 向量和数组

1. What does “Caveat emptor!” mean? 
2. What is the default meaning of copying for class objects? 拷贝的默认含义是“拷贝所有的数据成员”
3. When is the default meaning of copying of class objects appropriate? When is it inappropriate? 
4. What is a copy constructor? 实现拷贝操作的特定类型的构造函数,用另一个对象来初始化
5. What is a copy assignment? 赋值定义了当一个兑现赋予同类型另一个对象时做什么
6. What is the difference between copy assignment and copy initialization? 
7. What is shallow copy? What is deep copy? 浅拷贝:只拷贝指针,因此两个指针可能指向同一个对象。 深拷贝:将拷贝指针指向的数据,因此两个指针将指向不同的对象
8. How does the copy of a vector compare to its source?
9. What are the five “essential operations” for a class? 构造函数、默认构造函数、拷贝构造函数、拷贝赋值函数、析构函数
10. What is an explicit constructor? Where would you prefer one over the (default) alternative? 显示构造函数:只能用于对象构造而不能用于隐式转换(只有一个参数的构造函数定义了一个从其参数类型向该函数所属类型的转换)
11. What operations may be invoked implicitly for a class object? 构造函数默认是非显示的
12. What is an array? 数组:在内存空间中顺序排列的同类型对象的集合
13. How do you copy an array?
14. How do you initialize an array? 数组通过与其类型相匹配的值列表进行初始化
15. When should you prefer a pointer argument over a reference argument? Why?
16. What is a C-style string? C风格的字符串:以0结尾的字符串数组
17. What is a palindrome? 回文是一种单词,它按照顺序以及逆序的方式拼写所得的结果是一致的

 

第十九章 向量、模板和异常

1. Why would we want to change the size of a vector? 读取未知数量的数值
2. Why would we want to have different element types for different vectors?
3. Why don’t we just always define a vector with a large enough size for all eventualities? 因为没有足够的内存或者避免由于分配的内存过多造成的浪费
4. How much spare space do we allocate for a new vector?
5. When must we copy vector elements to a new location?
6. Which vector operations can change the size of a vector after construction?  resize()
7. What is the value of a vector after a copy? 
8. Which two operations define copy for vector?
9. What is the default meaning of copy for class objects?
10. What is a template? 模板是一种机制,它使程序员能够使用数据类型作为一个类或函数的参数。当我们将数据类型作为参数时,编译器将会根据参数特定类型的类或函数
11. What are the two most useful types of template arguments? typename, class 
12. What is generic programming? 使用模板。泛型编程:编写能够正确处理各种不同数据类型参数的代码,只要参数的数据类型满足特定的语法和语义要求
13. How does generic programming differ from object-oriented programming? 泛型编程:以模板为基础,依靠程序编译时的解析。 面向对象的编程:以类层次结构和虚函数为基础,依靠程序运行时的解析。
14. How does array differ from vector?
15. How does array differ from the built-in array?
16. How does resize() differ from reserve()? resize()是修改size,即挡球拥有元素的个数。reserve()则是修改容量,即可以存储的元素的总数
17. What is a resource? Define and give examples. 资源:资源的使用者必须向系统中的“资源管理者”归还资源,并由“资源管理者”负责资源的回收。 内存,文件句柄,线程句柄,窗口
18. What is a resource leak? 内存泄露:内存资源因为意外使得内存的释放没有发生
19. What is RAII? What problem does it address? 获取资源即初始化:通过对象的构造函数获取资源,并通过对应的析构函数释放资源。 能够解决内存泄露问题
20. What is unique_ptr good for? 当异常发生时,能够销毁类的对象
 

第二十章 容器和迭代器

1. Why does code written by different people look different? Give examples.
2. What are simple questions we ask of data? 我们需要如何处理数据?
3. What are a few different ways of storing data?
4. What basic operations can we do to a collection of data items?
5. What are some ideals for the way we store our data?
6. What is an STL sequence? 数据集合就是一个序列
7. What is an STL iterator? What operations does it support? 迭代器:一个可以标识序列中元素的对象。 操作:==, != ,*P, *p = value, val = *p, ++p
8. How do you move an iterator to the next element?  ++
9. How do you move an iterator to the previous element?
10. What happens if you try to move an iterator past the end of a sequence?
11. What kinds of iterators can you move to the previous element?
12. Why is it useful to separate data from algorithms? 代码不再需要知道存储和访问数据的不同方法;只需要对迭代器有一定了解
13. What is the STL? C++标准库为处理数据序列提供了一个专门的框架
14. What is a linked list? How does it fundamentally differ from a vector? 链表:序列在内存中的排列不一定都是连续的
15. What is a link (in a linked list)? link由一个元素和一个或者多个指针组成
16. What does insert() do? What does erase() do? 插入和删除元素
17. How do you know if a sequence is empty? 通过比较begin()和end()测试是否为空
18. What operations does an iterator for a list provide?   *,++,==,!=,--
19. How do you iterate over a container using the STL?  for(iterator pos = begin(); pos!=end(); ++pos)
20. When would you use a string rather than a vector? 处理字符类型的元素时才会考虑string
21. When would you use a list rather than a vector?  在不移动元素的情况下对其进行插入或删除操作——列表
22. What is a container?  container: an object that holds elements(other objects)
23. What should begin() and end() do for a container?  begin():返回指向容器最开始位置元素的指针; end():返回指向容器最后一个元素+1的指针
24. What containers does the STL provide?  vector, list, deque, map, multimap, unodered_map, unordered_multimap, set, multiset, unordered_set, unordered_multiset, array
25. What is an iterator category? What kinds of iterators does the STL offer?  输入、输出、向前、双向、随机访问
26. What operations are provided by a random-access iterator, but not a bidirectional iterator?  []来完成对元素值的读取和写入
 

第二十一章 算法和映射

1. What are examples of useful STL algorithms?
2. What does find() do? Give at least five examples. 找出某个元素在某个范围首次出现的位置
3. What does count_if() do? 满足某个条件的元素的个数
4. What does sort(b,e) use as its sorting criterion? 小于
5. How does an STL algorithm take a container as an input argument?
6. How does an STL algorithm take a container as an output argument?
7. How does an STL algorithm usually indicate “not found” or “failure”?
8. What is a function object? 函数对象:一种能够实现函数功能的对象。需要对象是因为对象能够存储数据
9. In which ways does a function object differ from a function? 函数对象,能够承载所要的数据
10. What is a predicate? 谓词:一种返回true或false的函数
11. What does accumulate() do? 累加序列中的值
12. What does inner_product() do? 将两个序列的对应元素相乘并将结果累加
13. What is an associative container? Give at least three examples. 关联容器:关联容器中的元素时按关键字来保存和访问  map, set, unorder_, multi
14. Is list an associative container? Why not?
15. What is the basic ordering property of binary tree?  左小右大
16. What (roughly) does it mean for a tree to be balanced? 一棵树中的每个节点的左、右子树的节点数大致相同
17. How much space per element does a map take up?
18. How much space per element does a vector take up?
19. Why would anyone use an unordered_map when an (ordered) map is available? 查找速度快
20. How does a set differ from a map? 没有值的map
21. How does a multimap differ from a map?
22. Why use a copy() algorithm when we could “just write a simple loop”?
23. What is a binary search?
 

 

 


 

更多推荐

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