State whether each of the following is true or false. If false, explain why. Assume the state

ment using std::cout; is used.

a) Comments cause the computer to print the text after the // on the screen when the program is executed.

b) The escape sequence \n, when output with cout and the stream insertion operator,causes the cursor to position to the beginning of the next line on the screen.

c) All variables must be declared before they’re used.

d) All variables must be given a type when they’re declared.

e) C++ considers the variables number and NuMbEr to be identical.

f) Declarations can appear almost anywhere in the body of a C++ function.

g) The remainder operator (%) can be used only with integer operands.

h) The arithmetic operators *, /, %, + and – all have the same level of precedence.

i) A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator.

a) False. Comments do not cause any action to be performed when the program is exe

cuted. They’re used to document programs and improve their readability.

b) True.

c) True.

d) True.

e) False. C++ is case sensitive, so these variables are different.

f) True.

g) True.

h) False. The operators *, / and % have the same precedence, and the operators + and - have

a lower precedence.

i) False. One statement with cout and multiple \n escape sequences can print several lines.

State whether each of the following is true or false. If false, explain why.

a) By convention, function names begin with a capital letter and all subsequent words in

the name begin with a capital letter.

b) Empty parentheses following a function name in a function definition indicate that the

function does not require any parameters to perform its task.

c) Data members or member functions declared with access specifier private are accessi

ble to member functions of the class in which they’re declared.

d) Variables declared in the body of a particular member function are known as data mem

bers and can be used in all member functions of the class.

e) Every function’s body is delimited by left and right braces ({ and }).

f) The types of arguments in a function call must be consistent with the types of the cor

responding parameters in the function’s parameter list.

3.2

a) False. Function names begin with a lowercase letter and all subsequent words in the

name begin with a capital letter. b) True. c) True. d) False. Such variables are local variables and can

be used only in the member function in which they’re declared. e) True. f) True.

State whether each of the following is true or false. If the answer is false, explain why.

a) The default case is required in the switch selection statement.

b) The break statement is required in the default case of a switch selection statement to

exit the switch properly.

c) The expression (x > y && a < b) is true if either the expression x>y is true or the ex

pression a<b is true.

d) An expression containing the || operator is true if either or both of its operands are true

a) False. The default case is optional. Nevertheless, it’s considered good software engi

neering to always provide a default case.

b) False. The break statement is used to exit the switch statement. The break statement

is not required when the default case is the last case. Nor will the break statement be

required if having control proceed with the next case makes sense.

c) False. When using the && operator, both of the relational expressions must be true for

the entire expression to be true.

d) True.

7.2

(True or False) State whether the following are true or false. If the answer is false, explain

why.

a) A given array can store many different types of values.

b) An array subscript should normally be of data type float.

c) If there are fewer initializers in an initializer list than the number of elements in the ar

ray, the remaining elements are initialized to the last value in the initializer list.

d) It’s an error if an initializer list has more initializers than there are elements in the array.

7.2

a) False. An array can store only values of the same type.

b) False. An array subscript should be an integer or an integer expression.

c) False. The remaining elements are initialized to zero.

d) True.

(True or False) Determine whether each of the following is true or false. If false, explain why.

a) To refer to a particular location or element within an array, we specify the name of the

array and the value of the particular element.

b) An array definition reserves space for an array.

c) To reserve 100 locations for integer array p, you write

p[100];

d) A for statement must be used to initialize the elements of a 15-element array to zero.

e) Nested for statements must be used to total the elements of a two-dimensional array.

State whether each of the following is true or false. If the answer is false, explain why.

a) The address operator & can be applied only to constants and to expressions.

b) A pointer that is declared to be of type void* can be dereferenced.

c) A pointer of one type can’t be assigned to one of another type without a cast operation.

a) False. The operand of the address operator must be an lvalue; the address operator can

not be applied to literals or to expressions that result in temporary values.

b) False. A pointer to void cannot be dereferenced. Such a pointer does not have a type

that enables the compiler to determine the type of the data and the number of bytes of

memory to which the pointer points.

c) False. Pointers of any type can be assigned to void pointers. Pointers of type void can

be assigned to pointers of other types only with an explicit type cast.

(True or False) State whether the following are true or false. If false, explain why.

a) Two pointers that point to different built-in arrays cannot be compared meaningfully.

b) Because the name of a built-in array is implicitly convertible to a pointer to the first el

ement of the built-in array, built-in array names can be manipulated in the same man

ner as pointers.

State whether each of the following is true or false. If false, explain why.

a) Base-class constructors are not automatically inherited by derived classes.

b) A has-a relationship is implemented via inheritance.

c) A Car class has an is-a relationship with the SteeringWheel and Brakes classes.

d) When a derived-class object is destroyed, the destructors are called in the reverse order

of the constructors.

11.2

a) True. b) False. A has-a relationship is implemented via composition. An is-a relationship

is implemented via inheritance. c) False. This is an example of a has-a relationship. Class Car has an

is-a relationship with class Vehicle. d) True.

====下

(True or False) State whether each of the following is true or false. If the answer is false, ex

plain why.

a) The stream member function flags with a long argument sets the flags state variable

to its argument and returns its previous value.

b) The stream insertion operator << and the stream extraction operator >> are overloaded

to handle all standard data types—including strings and memory addresses (stream in

sertion only)—and all user-defined data types.

c) The stream member function flags with no arguments resets the stream’s format state.

d) Input with the stream extraction operator >> always skips leading white-space characters

in the input stream, by default.

e) The stream member function rdstate returns the current state of the stream.

f) The cout stream normally is connected to the display screen.

g) The stream member function good returns true if the bad, fail and eof member func

tions all return false.

h) The cin stream normally is connected to the display screen.

i) If a nonrecoverable error occurs during a stream operation, the bad member function

will return true.

j) Output to cerr is unbuffered and output to clog is buffered.

k) Stream manipulator showpoint forces floating-point values to print with the default six

digits of precision unless the precision value has been changed, in which case floating

point values print with the specified precision.

l) The ostream member function put outputs the specified number of characters.

m) The stream manipulators dec, oct and hex affect only the next integer output operation.

13.2

a) False. The stream member function flags with a fmtflags argument sets the flags state

variable to its argument and returns the prior state settings. b) False. The stream insertion and

stream extraction operators are not overloaded for all user-defined types. You must specifically pro

vide the overloaded operator functions to overload the stream operators for use with each user-de

fined type you create. c) False. The stream member function flags with no arguments returns the

current format settings as a fmtflags data type, which represents the format state. d) True. e) True.

f) True. g) True. h) False. The cin stream is connected to the standard input of the computer,

which normally is the keyboard. i) True. j) True. k) True. l) False. The ostream member function

put outputs its single-character argument. m) False. The stream manipulators dec, oct and hex set

the output format state for integers to the specified base until the base is changed again or the pro

gram terminates.

State whether each of the following is true or false. If false, explain why. Assume the state

ment using std::cout; is used.

a) Comments cause the computer to print the text after the // on the screen when the program is executed.

b) The escape sequence \n, when output with cout and the stream insertion operator,causes the cursor to position to the beginning of the next line on the screen.

c) All variables must be declared before they’re used.

d) All variables must be given a type when they’re declared.

e) C++ considers the variables number and NuMbEr to be identical.

f) Declarations can appear almost anywhere in the body of a C++ function.

g) The remainder operator (%) can be used only with integer operands.

h) The arithmetic operators *, /, %, + and – all have the same level of precedence.

i) A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator.

a) False. Comments do not cause any action to be performed when the program is exe

cuted. They’re used to document programs and improve their readability.

b) True.

c) True.

d) True.

e) False. C++ is case sensitive, so these variables are different.

f) True.

g) True.

h) False. The operators *, / and % have the same precedence, and the operators + and - have

a lower precedence.

i) False. One statement with cout and multiple \n escape sequences can print several lines.

State whether each of the following is true or false. If false, explain why.

a) By convention, function names begin with a capital letter and all subsequent words in

the name begin with a capital letter.

b) Empty parentheses following a function name in a function definition indicate that the

function does not require any parameters to perform its task.

c) Data members or member functions declared with access specifier private are accessi

ble to member functions of the class in which they’re declared.

d) Variables declared in the body of a particular member function are known as data mem

bers and can be used in all member functions of the class.

e) Every function’s body is delimited by left and right braces ({ and }).

f) The types of arguments in a function call must be consistent with the types of the cor

responding parameters in the function’s parameter list.

3.2

a) False. Function names begin with a lowercase letter and all subsequent words in the

name begin with a capital letter. b) True. c) True. d) False. Such variables are local variables and can

be used only in the member function in which they’re declared. e) True. f) True.

State whether each of the following is true or false. If the answer is false, explain why.

a) The default case is required in the switch selection statement.

b) The break statement is required in the default case of a switch selection statement to

exit the switch properly.

c) The expression (x > y && a < b) is true if either the expression x>y is true or the ex

pression a<b is true.

d) An expression containing the || operator is true if either or both of its operands are true

a) False. The default case is optional. Nevertheless, it’s considered good software engi

neering to always provide a default case.

b) False. The break statement is used to exit the switch statement. The break statement

is not required when the default case is the last case. Nor will the break statement be

required if having control proceed with the next case makes sense.

c) False. When using the && operator, both of the relational expressions must be true for

the entire expression to be true.

d) True.

7.2

(True or False) State whether the following are true or false. If the answer is false, explain

why.

a) A given array can store many different types of values.

b) An array subscript should normally be of data type float.

c) If there are fewer initializers in an initializer list than the number of elements in the ar

ray, the remaining elements are initialized to the last value in the initializer list.

d) It’s an error if an initializer list has more initializers than there are elements in the array.

7.2

a) False. An array can store only values of the same type.

b) False. An array subscript should be an integer or an integer expression.

c) False. The remaining elements are initialized to zero.

d) True.

(True or False) Determine whether each of the following is true or false. If false, explain why.

a) To refer to a particular location or element within an array, we specify the name of the

array and the value of the particular element.

b) An array definition reserves space for an array.

c) To reserve 100 locations for integer array p, you write

p[100];

d) A for statement must be used to initialize the elements of a 15-element array to zero.

e) Nested for statements must be used to total the elements of a two-dimensional array.

State whether each of the following is true or false. If the answer is false, explain why.

a) The address operator & can be applied only to constants and to expressions.

b) A pointer that is declared to be of type void* can be dereferenced.

c) A pointer of one type can’t be assigned to one of another type without a cast operation.

a) False. The operand of the address operator must be an lvalue; the address operator can

not be applied to literals or to expressions that result in temporary values.

b) False. A pointer to void cannot be dereferenced. Such a pointer does not have a type

that enables the compiler to determine the type of the data and the number of bytes of

memory to which the pointer points.

c) False. Pointers of any type can be assigned to void pointers. Pointers of type void can

be assigned to pointers of other types only with an explicit type cast.

(True or False) State whether the following are true or false. If false, explain why.

a) Two pointers that point to different built-in arrays cannot be compared meaningfully.

b) Because the name of a built-in array is implicitly convertible to a pointer to the first el

ement of the built-in array, built-in array names can be manipulated in the same man

ner as pointers.

State whether each of the following is true or false. If false, explain why.

a) Base-class constructors are not automatically inherited by derived classes.

b) A has-a relationship is implemented via inheritance.

c) A Car class has an is-a relationship with the SteeringWheel and Brakes classes.

d) When a derived-class object is destroyed, the destructors are called in the reverse order

of the constructors.

11.2

a) True. b) False. A has-a relationship is implemented via composition. An is-a relationship

is implemented via inheritance. c) False. This is an example of a has-a relationship. Class Car has an

is-a relationship with class Vehicle. d) True.

====下

(True or False) State whether each of the following is true or false. If the answer is false, ex

plain why.

a) The stream member function flags with a long argument sets the flags state variable

to its argument and returns its previous value.

b) The stream insertion operator << and the stream extraction operator >> are overloaded

to handle all standard data types—including strings and memory addresses (stream in

sertion only)—and all user-defined data types.

c) The stream member function flags with no arguments resets the stream’s format state.

d) Input with the stream extraction operator >> always skips leading white-space characters

in the input stream, by default.

e) The stream member function rdstate returns the current state of the stream.

f) The cout stream normally is connected to the display screen.

g) The stream member function good returns true if the bad, fail and eof member func

tions all return false.

h) The cin stream normally is connected to the display screen.

i) If a nonrecoverable error occurs during a stream operation, the bad member function

will return true.

j) Output to cerr is unbuffered and output to clog is buffered.

k) Stream manipulator showpoint forces floating-point values to print with the default six

digits of precision unless the precision value has been changed, in which case floating

point values print with the specified precision.

l) The ostream member function put outputs the specified number of characters.

m) The stream manipulators dec, oct and hex affect only the next integer output operation.

13.2

a) False. The stream member function flags with a fmtflags argument sets the flags state

variable to its argument and returns the prior state settings. b) False. The stream insertion and

stream extraction operators are not overloaded for all user-defined types. You must specifically pro

vide the overloaded operator functions to overload the stream operators for use with each user-de

fined type you create. c) False. The stream member function flags with no arguments returns the

current format settings as a fmtflags data type, which represents the format state. d) True. e) True.

f) True. g) True. h) False. The cin stream is connected to the standard input of the computer,

which normally is the keyboard. i) True. j) True. k) True. l) False. The ostream member function

put outputs its single-character argument. m) False. The stream manipulators dec, oct and hex set

the output format state for integers to the specified base until the base is changed again or the pro

gram terminates.

【cpp上】课后正误小题的更多相关文章

  1. CF上的3道小题(2)

    CF上的3道小题(2) T1:CF630K Indivisibility 题意:给出一个数n,求1到n的数中不能被2到9中任意一个数整除的数. 分析:容斥一下,没了. 代码: #include < ...

  2. CF上的3道小题(1)

    CF上的3道小题 终于调完了啊.... T1:CF702E Analysis of Pathes in Functional Graph 题意:你获得了一个n个点有向图,每个点只有一条出边.第i个点的 ...

  3. 常让人误解的一道js小题

    一道小题引发的深思 今天无意中看到一个js笔试题,不由得想起初学js那会被各种题目狂虐的心酸,虽说现在也会被笔试题所虐,但毕竟比之前好了很多,下面就是我的个人理解,欢迎拍砖.指正: var x = 1 ...

  4. 一些js小题(一)

    一些js小题,掌握这些对于一些常见的面试.笔试题应该很有帮助: var a=10; function aa(){ alert(a); } function bb(){ aa(); } bb();//1 ...

  5. CSDN挑战编程——《金色十月线上编程比赛第二题:解密》

    金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...

  6. 关于理解python类的小题

    今天看了python部落翻译的一篇<一道python类的小题>文章,感觉挺有启发性,记录下来: print('A') class Person(object): print('B') de ...

  7. 项目在iOS11上遇到的小问题

    ​iOS11正式版出了这么久了,在忙完新版本开发,写下在iOS11上的一些小问题. 1  App图标不显示 现象:升级到iOS11系统下自己的项目桌面app图标不见了 出现这种情况我还以为自己手动删除 ...

  8. 20181014xlVBA获取小题零分名单

    Sub GetZeroName() Dim Dic As Object Const SUBJECT = "科目名称" Dim Key As String Dim OneKey Di ...

  9. 关于SQL的几道小题详解

    关于SQL的几道小题详解 当我们拿到题目的时候,并不是急于作答,那样会得不偿失的,而是分析思路,采用什么方法,达到什么目的,还要思考有没有简单的方法或者通用的方法等等,这样才会达到以一当十的效果,这样 ...

随机推荐

  1. 使用K8s的一些经验和体会

    坑 Java应用程序的奇怪案例 ​ 在微服务和容器化方面,工程师倾向于避免使用 Java,这主要是由于 Java 臭名昭著的内存管理.但是,现在情况发生了改变,过去几年来 Java 的容器兼容性得到了 ...

  2. SAP下载文档为乱码

    通过事物WE60下载的文档为乱码,主要原因是编码格式的不匹配,通常默认的编码格式为ANSI编码,那么我们需要将源码的编码格式转换成UTF-8,这样问题可以解决了.   附:编码格式介绍 不同的国家和地 ...

  3. 使用idea插件识别log文件的相关设置

    最近要读一些spring boot项目产生的log文件,众所周知,idea拥有强大的插件系统.当我打开log文件时,idea自动帮我推荐了ideolog这个插件. 但是当我安装好之后发现系统并不能完全 ...

  4. 1.2V升5V电源芯片,1.2V升3V的IC电路图方案

    镍氢电池就是典型的1.2V供电电源了,但是1.2V电压太低,需要电源芯片来1.2V升5V输出,或1.2V升3V输出稳压,1.2V单独难给其他芯片或者模块供电,即使串联1.2V*2=2.4V,也是因为电 ...

  5. 在.NET Core 中使用Quartz.NET

    Quartz.NET是功能齐全的开源作业调度系统,可用于最小的应用程序到大型企业系统. Quartz.NET具有三个主要概念: job:运行的后台任务 trigger:控制后台任务运行的触发器. sc ...

  6. Docker 如何动态给SpringBoot项目传参

    关于SpringBoot配置数据源 在项目开发中,我们往往需要配置多套不同的配置环境例如:本地开发.测试环境.部署环境.每一个环境的数据源配置可能都不同,因此需要写不同的数据源配置.如果用Docker ...

  7. expect的使用

    1. expect概述 1.1 expect的功能 脚本执行时,有时会需要人工进行交互输入,这时可以通过expect工具来实现自动交互. expect是一种shell解释器,但是expect可以在命令 ...

  8. vercel是什么神仙网站?

    Vercel? vercel是我用过的最好用的网站托管服务.本网站就是基于hexo引擎模板开发,托管在vercel上的. vercel类似于github page,但远比github page强大,速 ...

  9. 对话 CTO〡用声音在一起,听荔枝 CTO 丁宁聊 UGC 声音互动平台的技术世界 原创 王颖奇 极客公园 2018-12-01

    https://mp.weixin.qq.com/s/jfHFXZpzbAEbHKkCMSev6w 对话 CTO〡用声音在一起,听荔枝 CTO 丁宁聊 UGC 声音互动平台的技术世界 原创 王颖奇 极 ...

  10. P95、P99.9百分位数值——服务响应时间的重要衡量指标

    前段时间,在对系统进行改版后,经常会有用户投诉说页面响应较慢,我们看了看监控数据,发现从接口响应时间的平均值来看在500ms左右,也算符合要求,不至于像用户说的那么慢,岁很费解,后来观察其它的一些指标 ...