CS Final Review Quiz Question
True/False: If an rvalue reference refers to a memory location, that memory location becomes an lvalue.
True
True/False: One reason for using functions is to break programs into a set of manageable units, or modules
True
True/False: Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false
True
True/False: Some C++ operators cannot be overloaded by the programmer.
True
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
True/False: The expression *s-> is only meaningful if s is a pointer to a structure and p is a pointer that is a member of that structure
True
True/False: When a class contains a pointer to dynamically allocated memory, it a good idea to have the class overload the assignment operator.
True
True/False: when an operator's operands are of different data types, such a double and int, C++ automatically converts one of them so that they are the same data type
True
True/False: A class must have exactly one constructor
False
True/False: A derived class may not have any classes derived from it.
False
True/False: A member function of a derived class may not have the same name as a member function of a base class.
False
True/False: C++ permits you to overload the sizeof operator.
False
True/False: If a function f is a friend of a class A, and the class A is a friend of a class B, then the function f is able to access private members of B.
False
True/False: If the sub-expression on the left side of an && operator is true, the expression on the right side will not be checked
False
True/False: If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded also.
False
True/False: In an inheritance situation, you can't pass arguments to a base class constructor.
False
True/False: Relational operators connect two or more relational expressions into one, or reverse the logic of an expression
False
True/False: The ampersand (&) is used to dereference a pointer variable in C++.
False
True/False: The following C++ statement will assign 1.5 to the result variable int result = 3.0 / 2.0
False
True/False: The following pair of C++ statements is legal const double taxrate; taxRate = .05;
False
True/False: The following statements will not print anything. x = 5; if(x < 5) cout << "Hello "; cout << "world \n";
False
True/False: The following two statements both assign the value 5 to the variable dept 5 = dept; dept = 5;
False
True/False: The only difference bwteen C-strings and string objects is how they are declared and internally stored. They are used exactly the same way
False
True/False: The size of an array is the number of elements that have data stored in them
False
True/False: When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members.
False
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
True/False: When you overload the << operator, you must also overload the >> operator.
False
True/False: You can overload the conditional operator to make it function as an unconditional operator.
False
True/False: if a variable is defined as int sum; It may be written in the program code as sum or Sum, but not SUM
False
C++ is an example of a ________ programming language. A. mid-level B. non-structured C. high-level D. low-level E. binary
C. high-level
A ______ variable is declared outside of all functions
global
Which of the following statements will assign number a value from 90-100 A. number = rand() % 90 + 10; B. number = rand() % 11 + 90; C. number = rand() % 10 + 90; D. number = rand() % 90 + 11 E. none of these
number = rand() % 11 + 90;
The process of having a class contain an instance of another class is known as_________
object composition
The following 2 arrays string deptName[3] = {"Manufacturing", "Sales", "Business Office"}; double deptBudget[3] = [20000.0, 60000.0, 50000.0}; are an example of ________ arrays
parallel
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
The ___ stream manipulator can be used to establish a field width for the value immediately following it
setw
A _____ keeps track of dynamically-allocated memory and automatically deletes when it is no longer in use
smart pointer
True/False: The amount of memory used by an array depends upon the array's data type and how many elements it can hold.
true
True/False: The cin object can be used to input more than one value in a single statement.
true
True/False: The first item placed onto a stack is always the last item removed from the stack.
true
True/False: The following two statements will assign the same value to result: result = a + b * c; result = b * c + a;
true
True/False: the following two statements could be used interchangeably in a C++ program: // Program payroll /* Program payroll */
true
What will the following expression evaluate to? !( 6 > 7 || 3 == 4)
true
A for statement contains three expressions: initialization, test, and ______
update
You may define a(n) _______ in the initialization expression of a for loop
variable
Dynamic memory allocation occurs
when a variable is created at runtime
For data validation, it is best to use a(n) ______ loop
while
A static local variable is one
whose value is retained between function calls
Subscript numbering in C++ automatically starts at _________.
zero
A function can have ______ parameters, and it can have either zero or one return value(s).
zero to many
The ____ operator is known as the logical OR operator
||
____ are C++ operators that change their operands by one
++ and --
The ____ and ____ operators can respectively be used to increment and decrement a pointed variable
++, --
The expression 7%2 evaluates to
1
The expression 7/2 evaluates to
3
What value will be assigned to the variable number by the following statement? int number = 3.75;
3
A ________ is a container that provides quick access to elements at the front and the back of the list. A. stack B. queue C. deque D. All of these E. None of these
C. deque
What will the following code print? num = 8; cout << --num << " "; cout << num++ << " "; cout << num;
7 7 8
If the scores array is defined like this: int scores[ ] = {4, 7, 4, 8, 9}; what will the following statement display? cout << scores[4];
9
The ________ operator may be used to assign one object to another.
= (assignment)
The ____ operator is used in C++ to test for equality
==
The _____ operator always follows the cin object, and the _____ operator follows the cout object
>>, <<
the purpose of a memory address is to A. identify the location of a memory cell B. allow multitasking C. locate a program D. precent multitasking E. none of these
A. identify the location of a memory cell
Program code that can be evaluated to a value is called a(n) A. operation B. evaluator C. expression D. result E. line
C. expression
An array can store a group of values, but the values must be: A. All the same data type B. declared at the time the array is created C. constants D. numeric, not characters or strings E. None of these
A. all the same data type
On each iteration of the following range-based for loop for (int element : my array) cout << element << endl; the variable element holds A. an array value B. an array subscript C. an array name D. an array location E. NOTA
A. an array value
An operation that copes a value into a variable is called a(n) _______ operation A. assignment B. declaration C. equals D. cout E. copy
A. assignment
The ________ class constructor is called before the ________ class constructor. A. base, derived B. derived, base C. public, private D. private, public E. None of these
A. base, derived
A ________ stack or queue is implemented using linked lists. A. dynamic B. static C. deque-based D. floating point E. None of these
A. dynamic
The ____ statement executes one statement, or block of statements, if a condition is true and skips it, does nothing , if the condition is false A. if B. switch C. if/endif D. if/else if E. if/else
A. if
Characters or symbols that perform operations on one or more operands are A. operators B. program ops C. syntax D. op codes E. none of these
A. operators
The while loop has two important parts: a condition that is tested and a statement or block of statements that is A. repeated as long as the condition is true B. repeated until the condition becomes true C. done once if the condition is true D. always done at least once, then repeated if the condition is true E. always skipped
A. repeated as long as the condition is true
In programming terms, a group of characters inside a set of double quotation marks is called a A. string literal B. character literal C. character set D. any of these E. none of these
A. string literal
When the final value of an expression is assigned to a variable, it will be converted to A. the data type of the variable B. the smallest possible data type C. The data type of the expression D. the largest possible data type E. none of the above
A. the data type of the variable
____ Must be included in a program in order to use the cout object A. the iostream header file B. opening and closing braces C. a cout declaration D. strings E. none of these
A. the iostream header file
The term hardware refers to A. the physical components that make up a computer B. the fixed order of a program's instructions C. the difficulty of programming D. the way a computer's storage space is organized E. none of these
A. the physical components that make up a computer
Any time you use the new operator, it is good practice to ________. A. use delete afterwards to free the memory allocated by new B. use a preprocessor directive C. clear the data from the old operator D. All of the above E. None of the above
A. use delete afterwards to free the memory allocated by new
Memory locations that can hold data are called A. variables B. operators C. operands D. syntax E. none of these
A. variables
In the statement class Car:public Vehicle, which is the base class? A. Car B. Vehicle C. public D. class E. None of these
B. Vehicle
When a class contains a pointer to dynamically allocated memory, it is a good idea to equip the class with A. a dynamically allocated constructor. B. a copy constructor. C. a static constructor and an overloaded comparison operator. D. an inline constructor. E. NOTA
B. a copy constructor.
A situation in which every object of a class A has a pointer to an object of a class B, and the objects of the class B may outlive objects of class A, is called A. a has-A relation. B. aggregation. C. composition. D. an is=A relation. E. None of these
B. aggregation
The statements in the body of a do-while loop are executed A. exactly once B. at least once C. Only if the test condition is initially true D. until the test condition becomes true E. forever until the user hits the break key
B. at least once
A good reason for overloading an operator is to enable it to A. outperform its C language counterparts. B. be used with types defined by the programmer. C. operate on more operands than in its standard definition. D. operate on no operands. E. NOTA
B. be used with types defined by the programmer.
The ________ coordinates the computer's operations by fetching the next instruction and using control signals to regulate the other major computer components. A. operating system B. control unit C. instruction manager D. arithmetic and logic unit (ALU) E. traffic controller
B. control unit
Which of the following will cause the next output to begin on a new line? A. cout << "endl"; B. cout << endl; C. cout << endl; and cout << "/n"; but not cout << "endl"; D. cout << "/n"; E. all of these
B. cout << endl; note: \n is newline, /n is not
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? A. setRadius(2.5); B. myCircle.setRadius(2.5); C. Circle.setRadius(2.5); D. Circle(setRadius(2.5)); E. NOTA
B. myCircle.setRadius(2.5);
If you do not furnish a(n) ________, an automatic memberwise copy will be performed when one object is assigned to another object. A. overloaded constructor function B. overloaded assignment operator C. default constructor function D. overloaded copy operator E. NOTA
B. overloaded assignment operator
In C++, a value can be raised to a power by using the A. ^ operator B. pow function C. square function D. exp operator E. power operator
B. pow function
The computer's main memory is commonly known as: A. secondary storage B. random-access memory (RAM) C. direct-access memory (DAM) D. read-only memory (ROM) E. none of these
B. random-access memory (RAM)
The CPU includes A. the ALU and the I/O unit B. the arithmetic and logic unit (ALU) and the control unit C. the ALU and the main memory unit D. the I/O unit and the control unit E. All of these
B. the arithmetic and logic unit (ALU) and the control unit
If Circle is the name of a class, which of the following statements would create a Circle object named myCircle? A. myCircle Circle; B. myCircle Circle( ); C. Circle myCircle; D. Circle myCircle( ); E. NOTA
C. Circle myCircle;
_______ causes a program to wait until information is types at the keyboard and the Enter key is pressed A. a preprocessor B. the cout object C. The cin object D. an input device
C. The cin object
Hand tracing a program is A. a program run-time testing technique B. creating a drawing of what a program's output screen will look like C. a program debugging technique D. a program design technique E. none of the above
C. a program debugging technique
a variable must be defined A. in order to perform output B. and initialized at the same time C. before it can be used D. in every program E. in all of these cases
C. before it can be used
What literal(s) appear in the following C++ statement? int number = 4 + 8; A. 4 B. number C. both 4 and 8 D. 12 E. 8
C. both 4 and 8
When you derive a class from an existing class, you A. can add new data, but cannot add new functions. B. can add new functions, but cannot add new data. C. can add both new data and new functions. D. must add both new data and new functions. E. None of these
C. can add both new data and new functions.
It is a good idea to make a copy constructor's parameters ________ by specifying the ________ keyword in the parameter list. A. inline, inline B. static, static C. constant, const D. global, glob E. None of these
C. constant, const
Which of the following statements correctly deletes a dynamically allocated array pointed to by p? A. delete p; B. p delete[ ]; C. delete [ ] p; D. delete array p; E. none of these
C. delete [ ] p;
The ____ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be true or until the construct is exited without any test every evaluating to true A. if/not if B. if/else C. if/else if D. if/then E. if/endif
C. if/else if
A sentinel is a special value that A. is used for data validation B. must be Boolean C. marks the end of a list of values D. must be a negative number E. all of these
C. marks the end of a list of values
C++ allows you to overload A. compiler errors B. preprocessor directives C. operators and functions D. undefined variables E. NOTA
C. operators and functions
A(n) ________ is a set of instructions that tells the computer how to solve a problem. A. variable B. compiler C. program D. operator E. linker
C. program
The statements written by a programmer are called A. language elements B. object code C. source code D. syntax E. none of these
C. source code
A reason to overload the ________ is to write classes that have array-like behavior. A. parentheses ( ) B. curly braces { } C. square brackets [ ] D. scope resolution operator : : E. None of these
C. square brackets [ ]
Which of the following statements about ADT's are true? A. They specify the values the data type can hold B. They specify the operations that the data type can perform C. They hide the details of how the data type is implemented D. All of the above E. Both A and B
D. All of the above
The queue data structure is commonly applied in connection with A. managing the order of print jobs. B. communications software. C. operating systems. D. All of these E. None of these
D. All of these
Multiple Choice. A(n) ________ member function may be called by a statement in a function that is outside of the class. A. private B. inline C. constructor D. public E. declared
D. Public
C++ requires that a copy constructor's parameter be A. an integer data type. B. a floating-point data type. C. a pointer variable D. a reference to an object. E. NOTA
D. a reference to an object.
Which of the following definitions will allow the variable average to hold floating-point values? A. float average; B. auto average = 0.0; C. double average; D. all of the above E. float average; and double average; but not auto average = 0.0;
D. all of the above
An integrated development environment (IDE) normally includes A. a debugger B. a text editor C. a compiler D. all of these E. none of these
D. all of these
At the heart of a computer is its central processing unit. The CPU's job is: A. Produce some result B. carry out the operations commanded by the instructions C. fetch instructions D. all of these E. none of these
D. all of these
A ______ variable can only hold one of two values: true or false A. binary B. single precision C. char D. T/F E. bool
D. bool
Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks? A. cin.ignore(0 B. cin >> C. cin.get() D. getline() E. both getline(0 and cin >> , but not cin.get() or cin.inore()
D. getline()
________ Can be used to override the rules of operator precedence A. some operators B. associativity C. nothing D. parentheses E. operands
D. parentheses
Creating a program requires many steps. three of these are A. input, processing, and output. B. keywords, operators, and punctuation. C. syntax, logic, and error handling. D. program design, writing source code, and testing. E. none of these
D. program design, writing source code, and testing.
________ is used in a C++ program to mark the end of a statement, or to separate items in a list. A. a keyword B. a separator C. an operator D. punctuation E. a blank space
D. punctuation
Which of the following doubles the value stored in answer A. answer *= 2; B. answer += 2; C. answer = answer * 2; D. all of the above E. Both answer*=2; and answer = answer * 2; but not answer+=2;
E. Both answer*=2; and answer = answer * 2; but not answer+=2;
Which of the following is/are valid C++ identifiers? A. aVeryLongVariableName B. last-name C. department_9 D. all of the above E. Both department_9 and aVeryLongVariableName but not last-name
E. Both department_9 and aVeryLongVariableName but not last-name
Which of the following will evaluate to 2.5? A. 5/static_cast<double>(2) B. static_cast<double>(5/2) C. static_cast<double>(5)/2 D. all three of these E. Both static_cast<double>(5)/2 and 5/static_cast<double>(2), but not static_cast<double>(5/2)
E. Both static_cast<double>(5)/2 and 5/static_cast<double>(2), but not static_cast<double>(5/2)
You can assign the contents of one array to another by using A. the assignment operator B. the equality operator C. both array names D. the assignment operator and both array names E. NOTA
E. NOTA
Arguments are passed to the base class destructor function by the ________ class ________ function. A. derived, constructor B. derived, destructor C. base, constructor D. base, destructor E. None of these
E. None of these
A set of well-defined steps for performing a task or solving a problem is known as a A. hierarchy chart B. flowchart C. solution engine D. software engineering E. algorithm
E. algorithm
Which of the following keywords is/are the names of C++ data types? A. double B. short C. long D. bool E. all of these
E. all of these
To use an output file in a C++ program you must A. make sure the file already exists B. create a file stream object that will "point to" (i.e, reference) the file C. open the file D: AOTA E. do create a file stream object that will "point to" (i.e, reference) the file and open the file, but not make sure the file already exists
E. do create a file stream object that will "point to" (i.e, reference) the file and open the file, but not make sure the file already exists
A constructor may have a return type of A. int B. bool C. void D. any of these E. none of these
E. none of these
If s1 and s2 are string objects, s1 == s2 is true when A. s1 = "cat" and s2 = "cat " B. s1 = "dog" and s2 = "DOG" C. s1 = "lion" and s2 = "lioness" D. none of these because string objects cannot be compared with relational operators E. none of these because in each case one or more characters in the strings have different ASCII codes
E. none of these because in each case one or more characters in the strings have different ASCII codes
________ members of a base class are never accessible to a derived class.
Private
The statement cout << &num1; will output
The memory address of the variable called num1
True/False: A class declaration describes an object, but does not create any objects.
True
True/False: A constructor is a public class function that is automatically invoked (i.e. called) whenever a class object is created
True
True/False: A derived class may become a base class, if another class is derived from it.
True
True/False: A static member variable can be used when there are no objects of the class in existence.
True
True/False: A temporary value in a program can be referred to by at most one lvalue reference
True
True/False: An expression in a C++ if statement thats evaluates to 5, -5, or for that matter anything other than 0, is considered true
True
True/False: C++ does not perform array bounds checking
True
A pointer variable is designed to store
a memory address
To add up the values in a 2-dimensional array, it would be best to use
a nested for loop
A C++ member function that uses, but does not change, the value of a member variable is called a(n)___________
accessor (getter)
A variable that keeps a running total of data values is called a(n) ________
accumulator
Every byte in the computer's memory is assigned a unique ______
address
When the _____ is placed in front of a variable name, it returns the address of that variable
ampersand (&)
When the _____ is placed in front of the variable name, it returns the address of that variable.
ampersand (&)
In the following statement, what is 22.0? cout << sqrt(22.0);
an argument
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
What will the following statement do if x equal 17 and answer = 20? answer = x > 100 ? 0 : 1
assign 1 to answer
In OOP terminology, an objects member variables are often called its______ and its member functions are sometimes referred to as its ______
attributes, methods
A flag is a variable, usually of data type _____, that signals whether or not some condition exists
bool (A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. Using flag variable(user defined variable, not a predefined) you can control the flow of a function or statement, allowing you to check for certain conditions while your function progresses. example: using errorFound to check if an error is found in a list)
When only a copy of an argument is passed to a function, it is said to be passed _____
by value
A function_______ is a statement that causes a function to execute
call
A statement that displays the address of num 1 is
cout << &num1;
A constructor that does not require that any arguments be passed to it is called a(n) ______ constructor
default
A(n) _______ argument is one that is automatically passed to a parameter when the argument is left out of the function call
default
True/False: A while loop is somewhat limited, because the counter can only count up, not down
false
True/False: Any arithmetic operation may be performed on pointers
false
True/False: Both function headers and function calls must list the data types of all data being passed to the function
false
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
True/False: In C++ global and local numeric variables are initialized to zero by default
false
True/False: Once a value has been stored in a variable it cannot be changed.
false
True/False: The following C++ test checks if the variable child is in the range 3-12 if (child >= 3 && <= 12)
false
True/False: The following array definition is legal because C++ allows arrays to be implicitly sized int grades[ ];
false
True/False: The following statement is a valid C++ array definition double money[25.00];
false
True/False: The purpose of the compiler is to convert object code into source code.
false
True/False: To decrement a number means to increase its value
false
True/False: When a loop is nested inside another loop, the outer loop goes through all its iteration for each iteration of the inner loop
false
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
True/False: after carrying out the following two statements, sales will have been cerated as a one-dimensional array that can hold 20 double values typedef salesArray double[20]; salesArray sales;
false
True/False: the following is a legal C++ statement to define and initialize a variable: char firstName = "Jack";
false
True/False: the scope of a variable is the program it is defined in
false
True/false: In C++ If you attempt to store more data in an array than it can hold, the compiler will issue an error
false
True/False: ADT stands for Algorithmic Data Type
false (stands for abstract data type)
True/False: The following statements both declare the variable num to be an integer int num; INT num;
false; C++ is case-sensitive
To use files in a C++ program you must include the ________ header file.
fstream
Every C++ program must have a
function called main
________ allows us to create new classes based on existing classes.
inheritance
In a for statement, the ____ expression is executed only once
initialization
When the body of a member function is defined inside a class declaration, it is called a(n )__________ function
inline
When a program lets the user know that an invalid menu choice has been made, this is an example of
input validation
Each object of a class has its own copy of the class's _______
instance member variables
When three different objects of a particular class are created, they are said to be separate ________ of the class.
instances
To use stream manipulators, you should include the ________ header file.
iomanip
A destructor is a member function that______
is automatically called when an object is destroyed
List five elements that are common to all programming languages.
keywords, programmer-defined symbols, operators, punctuation, and syntax
The while loop is a(n) _____ loop, whereas a do-while loop is a(n) ______ loop
pretest, posttest
A function ____ eliminates the need to place the function definition before all calls to the function
prototype
The statement int *ptr; means
ptr is a pointer variable that will store the address of an integer variable
A(n)_______ member function may be called by a statement in a function that is outside of the class
public
An object typically hides it data, but allows outside code to access through its______
public member functions
The expression x < y is called a(n) _____ expression
relational
A void function is one that
returns no value
A ________ is used to mark the end of a complete C++ programming statement.
semicolon
Accessors are sometimes called ________ functions and mutators are sometimes called ________ functions.
set, set
The statement int*ptr = new int; acquires memory to hold an integer and then
sets ptr to point to the allocated memory
A(n) ________ is an abstract data type that stores and retrieves items in a last-in-first-out manner.
stack
A(n) _______ member variable may be accessed before any objects of the class have been declared
static
The statement cin >> *p;
stores the keyboard input into the variable pointed to by p
an overloaded function is one
that has the same name as another function
A pointer variable may be initialized with
the address of an existing variable of the appropriate type
If a variable occupies more than one byte of memory, its address is
the address of the first byte of storage allocated to it
In any program that uses the cin object, you must #include
the iostream header file
If dynamically allocated memory is not freed,
the system may run out of memory
The statement cout << *ptr; will output
the value stored in the variable whose address is contained in ptr
A dangling pointer is a pointer
to a block of memory that has been deleted
The default section of a switch statement performs a similar task as the ______ portion of an if/else if statement
trailing else
True/ False: Most of the lines in a program contain something meaningful; however, some of the lines may contain nothing at all
true
True/False: A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.
true
True/False: Although global variables can be useful, it is considered good programming practice to restrict your use of them
true
True/False: An array name is a pointer constant because the address it represents cannot be changed during run-time
true
True/False: An initialization expression may be omitted from the for loop if no initialization is required
true
True/False: Any of the following statements may be used to initialize the variable num to 7: int num = 7; int num(7); int num{7};
true
True/False: Assuming moreData is a Boolean variable, the following two tests are logically equivalent. if (moreData == true) if(moreData)
true
True/False: Before a computer can execute a program written in a high level language, such as C++, it must be translated into object code.
true
True/False: By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
true
True/False: Each individual element of an array can be accessed by the array name and an element number, called a subscript
true
True/False: Elements of vectors can be accessed by using the vector name and a subscript, similar to how array elements are accessed
true
True/False: Object-oriented programming is centered around objects that include both data and the functions that operate on them
true