CSE-100 Midterm 2 Review

5.0(1)
studied byStudied by 9 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/156

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

157 Terms

1
New cards

________ are C++ operators that change their operands by one.

++ and —

2
New cards

True/False: To decrement a number means to increase its value.

False

3
New cards

The ++ operator (3 part)

A) is a unary operator.
B) adds one to the value of its operand.
C) can operate in prefix or postfix mode.

4
New cards

What will the following code print?
num = 8;
cout << --num << " ";
cout << num++ << " ";
cout << num;

7 7 8

5
New cards

The while loop has two important parts: a condition that is tested and a statement or block of statements that is _________

epeated as long as the condition is true

6
New cards

True/False: The block of code in the body of a while statement can contain an unlimited number of statements, provided they are enclosed in a set of braces.

True

7
New cards

True/False: A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.

False

8
New cards

True/False: A while loop is somewhat limited, because the counter can only count up, not down.

False

9
New cards

The while loop is a(n) ________ loop, whereas the do-while loop is a(n) ________ loop.

pretest, post test

10
New cards

The statements in the body of a do-while loop are executed

at least once

11
New cards

A sentinel is a special value that

marks the end of a list of values

12
New cards

A for statement contains three expressions: initialization, test, and

update

13
New cards

In a for statement, the ________ expression is executed only once

initialization

14
New cards

True/False: An initialization expression may be omitted from the for loop if no initialization is required

True

15
New cards

You may define a(n) ________ in the initialization expression of a for loop.

Variable

16
New cards

True/False: When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop

False

17
New cards

A variable that keeps a running total of data values is called a(n)

Accumulator

18
New cards

For data validation, it is best to use a(n)

while loop

19
New cards

To use files in a C++ program you must include the ________ header file

fstream

20
New cards

To use an output file in a C++ program you must

1.) create a file stream object that will "point to" (i.e. reference) the file.
2.) open the file.

21
New cards

To ________ a value means to increase it.

increment

22
New cards

The -- operator

A) is a unary operator.
B) subtracts one from the value of its operand.
C) must have a value, such as a variable, as its operand.
D) can be used in either prefix or postfix mode.

23
New cards

What will the following code print?
num = 5;
cout << num++ << " ";
cout << num-- << " ";
cout << --num;

5 6 4

24
New cards

The while loop has two important parts: a condition that is tested and a statement or block of statements that is executed

as long as the condition is true

25
New cards

If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur.

infinite loop

26
New cards

True/False: A while loop is somewhat limited because the counter can only be incremented or decremented by one each time through the loop.

False

27
New cards

A(n) ________ is a variable that controls the number of times a loop iterates.

loop control variable

28
New cards

A(n) ________ is a variable that is regularly incremented or decremented each time a loop iterates.

counter

29
New cards

True/False: When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop.

True

30
New cards

A(n) ________ is a special value that marks the end of a list of values.

sentinel

31
New cards

The do-while loop is a(n) ________ loop, whereas the while loop is a(n) ________ loop.

post test, pretest

32
New cards

True/False: You can nest a for loop inside another for loop, but cannot nest a while loop inside another while loop or a do-while loop inside another do-while loop

False

33
New cards

The statements in the body of a do-while loop are executed

at least once

34
New cards

True/False: Before beginning to add value to it, an accumulator should be initialized to 1.

False

35
New cards

The ________ statement causes a loop to terminate early.

break

36
New cards

If a while loop has no braces around the body of the loop

the loop body contains just one statement

37
New cards

The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop.

for

38
New cards

The ideal type of loop to use for repeating a menu is a(n) ________ loop

do-while

39
New cards

To use files in a C++ program you must include the ________ header file

fstream

40
New cards

In order for a C++ program to read data from a file

A) the file must already exist.
B) the program must define a file stream object that can "point to" (i.e., reference) the file.
C) the program must open the file.

41
New cards

Breaking a program up into a set of manageable sized functions is called ________ programming

modular

42
New cards

A function ________ includes the statements that make up the function

definition

43
New cards

A function other than the main function is executed

whenever it is called

44
New cards

True/False: A function can have zero to many parameters and either zero or one return value(s)

True

45
New cards

In a function header, in addition to the name of the function, you are required to furnish

A) a data type for each parameter.
B) an identifier name for each parameter.
C) the data type of the return value

46
New cards

In a function prototype, in addition to the name of the function, you are required to furnish

A) a data type for each parameter.

B) the data type of the return value.

47
New cards

In a function call, in addition to the name of the function, you are required to furnish

an identifier name or constant for each argument.

48
New cards

A void function is one that

returns no value.

49
New cards

True/False: Functions are ideal for use in menu-drive programs. When a user selects a menu item, the program can call an appropriate function to carry out the user's choice

True

50
New cards

A ________ variable is defined inside the body of a function and is not accessible outside that function.

local

51
New cards

The value in ________ local variable is retained between function calls.

A static

52
New cards

True/False: When a function just needs to use a copy of an argument passed to it, the argument should normally be passed by value.

True

53
New cards

When used as a parameter, a ________ variable allows a function to access and modify the original argument passed to it

reference

54
New cards

True/False: It is possible for a function to have some parameters with default arguments and some
without.

True

55
New cards

Two or more functions may have the same name provided that

their parameter lists are different

56
New cards

When more than one function has the same name they are called ________ functions

overloaded

57
New cards

The ________ statement causes a function to end and the flow of control to move back to the point where the function call was made.

return

58
New cards

True/False: A function with a return type of bool must return a value of either true or false.

True

59
New cards

The ________ function causes the entire program to terminate, regardless of which function or control mechanism is executing

exit()

60
New cards

A ________ is a program module whose purpose is to test other modules by calling them

driver

61
New cards

True/False: One reason for using functions is to break programs into a set of manageable units, or modules.

True

62
New cards

A function ________ is a statement that causes a function to execute

call

63
New cards

A void function is one that

returns no value

64
New cards

True/False: If a function has no return statement, the flow of control moves to the next function in the file when the closing brace of the function body is reached.

False

65
New cards

A(n) ________ is information that is passed to a function, and a(n) ________ is a special variable that receives and holds that information.

argument, parameter

66
New cards

A function can have ________ parameters, and it can have either zero or one return value(s)

zero to many

67
New cards

True/False: When you make a function call, the order of the arguments you send does not matter as long as the number of arguments matches the number of parameters the function has

False

68
New cards

When only a copy of an argument is passed to a function, it is said to be passed

by value

69
New cards

When a function needs access to an original argument passed to it, for example in order to change its value, the argument needs to be

passed into a reference parameter

70
New cards

A function ________ eliminates the need to place the function definition before all calls to the function

prototype

71
New cards

A ________ variable is declared outside all functions.

global

72
New cards

In the following statement, what is 22.0?
cout << sqrt(22.0);

An argument

73
New cards

True/False: Although global variables can be useful, it is considered good programming practice to
restrict your use of them

True

74
New cards

True/False: Both function headers and function calls must list the data types of all data being passed to the function

False

75
New cards

A(n) ________ argument is one that is automatically passed to a parameter when the argument is left out of the function call.

default

76
New cards

True/False: In C++ global and local numeric variables are initialized to zero by default.

FalseA static local variable is one

77
New cards

A static local variable is one

whose value is retained between function calls

78
New cards

An overloaded function is one

that has the same name as another function.

79
New cards

True/False: You may use the exit() function to return the flow of control from a function back to main() regardless of where the function was called from.

False

80
New cards

A ________ is a dummy function that is called instead of the actual function it represents, to test that the call to and return from the function are working correctly.

stub

81
New cards

True/False: Object-oriented programming is centered around objects that include both data and the functions that operate on them.

True

82
New cards

True/False: ADT stands for Algorithmic Data Type

False

83
New cards

Which of the following statements about ADTs are true.

A) They specify the values the data type can hold.
B) They specify the operations the data type can perform.
C) They hide the details of how the data type is implemented

84
New cards

True/False: A class declaration provides a pattern for creating objects, but doesn’t make any objects.

True

85
New cards

An object typically hides its data, but allows outside code to access it through its

public member functions

86
New cards

In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its ________.

attributes, methods

87
New cards

When three different objects of a class are created, they are said to be separate ________ of the class.

instances

88
New cards

When the body of a member function is defined inside a class declaration, it is called a(n) ________ function.

inline

89
New cards

True/False: A constructor is a public class function that is automatically invoked (i.e., called) whenever a class object is created

True

90
New cards

True/False: A class must have exactly one constructor.

False

91
New cards

A constructor may have a return type of

None

92
New cards

A constructor that does not require that any arguments be passed to it is called a(n) ________ constructor.

default

93
New cards

A destructor is a member function that

is automatically called when an object is destroyed

94
New cards

A(n) ________ member function may be called by a statement in a function that is outside of the class.

public

95
New cards

A C++ member function that uses, but does not change, the value of a member variable is called

an accessor

96
New cards

Accessors are sometimes called ________ functions and mutators are sometimes called ________ functions.

get, set

97
New cards

If Circle is the name of a class, which of the following statements would create a Circle object named myCircle?

Circle myCircle;

98
New cards

If setRadius is a Circle class function and myCircle is a Circle object, which of the following statements would set myCircle's radius to 2.5?

myCircle.setRadius(2.5);

99
New cards

True/False: A structure has member variables, like an object, but they are usually all public and accessed directly with the dot operator, instead of by calling member functions.

True

100
New cards

True/False: An Abstract data type (ADT) is a programmer-defined data type that specifies the values the type can hold, the operations that can be performed on them, and how the operations will be implemented.

False