C++ Midterm
The output of the statement: cout << tolower('$') << endl;
'$'
Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) || ( x <= 0) b. (x > 0) && ( x <= 0) c. (x >= 0) || (x == 0) d. (x > 0) && (x == 0)
(x > 0) || ( x <= 0)
Given the following function: int strange(int x, int y) { if (x > y) return x + y; else return x - y; } what is the output of the following statement? cout << strange(4, 5) << endl;
-1
The statement: return 8, 10; returns the value ____.
10
When you attach & after the dataType in the formal parameter list of a function, the variable following that dataType becomes a(n) ________ parameter.
reference
If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ______ function and use the appropriate reference parameters to return the values.
void
The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.
6
The statement: return 37, y, 2 * 3; returns the value ____.
6
What value is returned by the following return statement? int x = 5; return x + 1;
6
Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement? cout << next(next(5)) << endl;
7
Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____.
98
To use the predefined function tolower, the program must include the header file ____.
<cctype>
The standard header file for the abs(x)function is ____.
<cmath>
Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0) return x; else return x + 1;
True
Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.
True
The data type of a variable in a return statement must match the function type.
True
The following function heading in a C++ program is valid: int funcExp(int u, char v, float g)
True
Using functions greatly enhances a program's readability because it reduces the complexity of the function main.
True
____ consists of 65,536 characters
Unicode
which of the following is the newline character?
\n
Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared.
cout << tryMe(2.0, 3.0);
To generate a random number, you can use the function rand of the header file
cstdlib
The execution of a return statement in a user-defined function terminates the program.
false
The following return statement returns the value 10. return 10, 16;
false
A variable listed in a header is known as a(n) ____ parameter.
formal
The heading of the function is also called the ____.
function header
The object-oriented design, the first step in the problem-solving process is to identify the components called _______, which form the basis of the solution and to determine how they interact with one another
objects
in a C++ program, statements that begin with the symbol # are called _________ directives
preprocessor
_________ are executable statements the inform the user what to do
prompt lines
Main memory is called _____
random access memory
The term_____ describes a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.
short-circuit evaluation
a data type is called _______ if the variable or named constant of that type can store only one value at a time
simple
The value of the expression 7 + 8 <= 15 is
true
Putting ____ in front of a logical expression reverses the value of that logical expression.
!
Which of the following operators has the highest precedence? a. % b. = c. * d. !
!
Which of the following is the "not equal to" relational operator? a. ! b. != c. | d. &
!=
You can disable assert statements by using which of the following? a. #define <assert> b. #define NDEBUG c. #clear NDEBUG d. #include <cassert>
#define NDEBUG
For a program to use the assert function, it must include which of the following? a. #include <assertc> b. #include <cassert> c. #include NDEBUG d. #include <assert>
#include <cassert>
In C++, the mechanism that allows you to combine data and operations on the data into single unit is called a(n) _________
object-oriented programming
Which of the following statements generates a random number between 0 and 50? a.srand(time(10)); num = rand() % 50; b.srand(time(10)); num = rand()/50; c.srand(time(0)); num = rand() % 50; d.srand(time(0)); num = rand()50;
srand(time(0)); num = rand() % 50;
Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is _____. .
true
Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)
true
In C++, a function prototype is the function heading without the body of the function.
true
Functions that do not have a return type are called ____ functions.
void
an example of floating point data type is _____
double
Given the function prototype: float test(int, int, int); which of the following statements is legal?
cout << test(7, 14, 23);
Given the function prototype: double testAlpha(int u, char v, double t); which of the following statements is legal?
cout << testAlpha(5, 'A', 2);
Assembly language uses easy-to-remember instructions called
mnemonics
A variable or expression listed in a call to a function is called the ____.
actual parameter
A loop___________ is a set of statements that remains true each time the loop body is executed.
control variable
The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.
14.0
If the formal parameter list of a function is empty, the parentheses after the function name are not needed.
False
The function main is always compiled first, regardless of where in the program the function main is placed.
False
Which statement below about prototypes and headers is true? a. Headers should come before prototypes. b. Prototypes end with a semicolon, but headers do not. c. Headers end with a semicolon, but prototypes do not. d. Parameter names must be listed in the prototype, but not necessarily in the header.
Prototypes end with a semicolon, but headers do not.
Stream variables (for example, ifstream and ofstream) should be passed by _______ to a function.
Reference
____________ parameters are useful in three situations: • When the value of the actual parameter needs to be changed • When you want to return more than one value from a function • When passing the address would save memory space and time relative to copying a large amount of data
Referencereference
Given the following function prototype: int myFunc(int, int);, which of the following statements is valid? Assume that all variables are properly declared.
cout << myFunc(myFunc(7, 8), 15);
Which of the following function prototypes is valid? a. funcExp(int x, float v){}; b. int funcExp(int x, float v); c. int funcExp(x); d. funcExp(void);
int funcExp(int x, float v);
Which of the following function prototypes is valid? Select one: a. int funcTest(int x, int y, float z){} b. int funcTest(int, int y, float z) c. int funcTest(int, int, float); d. funcTest(int x, int y, float){};
int funcTest(int, int, float);
Given the following function prototype: int test(float, char);, which of the following statements is valid?
int u = test(5.0, '*');
The _____ of a function consists of the function name and its formal parameter list.
signature
Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.
2
______ programs perform specific task
application
The _______ of relational and logical operators is said to be from left to right.
associativity
the value of the expression 17 % 7 is _______
3
______ rules determine the meaning of instructions
Semantic
A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n)______
algorithm
____ loops are called posttest loops.
do...while
The _______ is the brain of the computer and the single most expensive piece of hardware in your personal computer
CPU
the digit 0 or 1 is called a binary digit, or ______
bit
The ____ statement can be used to eliminate the use of certain (flag) variables.
break
The _________ statement is typically used for two purposes: • To exit early from a loop. • To skip the remainder of a switch structure.
break
To output results correctly, the switch structure must include a(n) _____ statement after each cout statement, except the last cout statement.
break
a sequence of eight bits is called a _________
byte
Which of the following loops does not have an entry condition? a.sentinel-controlled while loop b.do...while loop c.EOF-controlled while loop d.for loop
do...while loop
Which of the following loops is guaranteed to execute at least once?
do...while loop
which of the following is reserved word in C++
char
C++ has a special name for the data types istream and ostream. they are called ________
classes
A program called a(n) _____ translates instructions written in high-level languages into machine code
compiler
The expression in an if statement is sometimes called a(n) ____.
decision maker
A(n) ____-controlled while loop uses a bool variable to control the loop.
flag
When a continue statement is executed in a ____, the update statement always executes.
for loop
the memory allocated for a float value is _______ bytes
four
C++ provides a header file called ______ which is used for file I/O
fstream
The term GB refers to ____
gigabyte
_____ languages include FORTRAN, COBOL, Pascal, C, C++, and Java
high-level
Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x <= 5) b. if (x = 5) c. if (x >= 5) d. if (x == 5)
if (x = 5)
A loop that continues to execute endlessly is called a(n) ____ loop.
infinite
Manipulators without parameters are part of the ______ header file
iostream
The function eof is a member of the data type
istream
What does <= mean?
less than or equal to
a program called a(n) _____ combines the object program with the programs from libraries
linker
A program that loads an executable program into main memory is called a(n) ______
loader
the memory space for a(n) ______ data value is 64 bytes
long long
What executes immediately after a continue statement in a while and do-while loop?
loop-continue test
In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).
looping
Several categories of computers exist, such as ______
mainframe, midsize, and micro
In C++, the dot is an operator called the ______ operator
member access
Main memory is an ordered sequence of items, called ______
memory cells
When one control statement is located within another, it is said to be ____.
nested
The ________ monitors the overall activity of the computer and provides services such as memory management, input/output activities and storage management
operating system
the _____ monitors the overall activity of the computer and provides services
operating system
the devices that the computer uses to display results are called _____ devices
output
the function ______ returns the next character in the input stream; it does not remove the character from the input stream
peek
the maximum number of significant digits is called the _______
precision
C++ comes with a wealth of functions called ______ functions that are written by other programmers
predefined
In a while and for loop, the loop condition is evaluated before executing the body of the loop. Therefore, while and for loops are called ________ loops
pretest
a(n) ______ is a sequence of zero or more characters
string
Dividing a problem into smaller subproblems is called _______ design
structured
A function _______ is a function that is not fully coded.
stub
a(n) _______ is a collection of statements, and when it is activated or executed, it accomplishes something
subprogram
A semicolon at the end of the for statement (just before the body of the loop) is a(n) _________ error.
syntax
The ______ rules of programming language tell you which statements are legal, or accepted by the programming language
syntax
Which executes first in a do...while loop?
the statement
the smaller individual unit of a program written in any language is called a(n) _________
token
A(n) ________ is a memory location whose contents can be changed
variable
The ASCII data set consists of _____ characters
128
What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4
4
Which of the following operators has the lowest precedence? a. && b. ! c. = d. ||
=
Which of the following is a relational operator? a. = b. ! c. == d. &&
==
the programming language C++ evolved from ________
C
______ signals represent information with a sequence of 0s and 1s
Digital
_________ is the process of planning and creating a program
Programming
A function prototype is ____.
a declaration, but not a definition
_______ represent information with a sequence of 0s and 1s
digital signals
Which of the following is a repetition structure in C++? a.switch b.do...while c.while...do d.if
do...while
The _______ type is C++'s method for allowing programmers to create their own simple data types
enumeration
Once an input stream enters a(n) ____ state, all subsequent input statements associated with that input stream are ignored, and the computer continues to execute the program, which produces erroneous results.
fail
When you want to process only partial data, you can use the stream function ________ to discard a portion of the input
ignore
When a value of one data type is automatically changed to another data type, a(n) ________ type coercion is said to have occurred
implicit
the devices that feed data and programs into computers are called ________ devices
input
the basic commands that a computer performs are _____, and performance arithmetic and logical operations
input, output, storage
A(n) ______ consists of data and the operations on those data
object
in ___________ design, the final program is a collection of interacting objects
object-oriented
In a ____ control structure, the computer executes particular statements depending on some condition(s).
selection
Putting a semicolon after the parentheses following the expression in an ifstatement (that is, before the statement) is a(n)__________ error.
semantic
_________ is a parameterized stream manipulator
setfill