C++
Assume you have defined a structure named Invoice. It contains an integer field named invoiceNumber and a double field named amount. What is the output of the following segment of code? Invoice myInvoice; myInvoice.invoiceNumber = 2245; myInvoice.amount = 100.00; if(myInvoice.invoiceNumber > 1000 || myInvoice.amount > 200.00 && myInvoice.amount < 500.00) cout << "Pay now" << endl; else cout << "Pay later" << endl;
"Pay now"
Which of the following operators can be overloaded?
&
. A default exception handler catches _____.
. any type of object not previously caught
When you use a class object with a function template, you must ______.
. define any operation used within the function template within the class
When you write a program in C++, an advantage of defining a constant to hold an array size is that _____.
. if you ever change the size of the array, you change the constant in a single location
The purpose of the set_new_handler() function is to _____.
. recognize out-of-memory situations, and call a function you specify
You can combine the arguments to the setf() function using _____.
. the bitwise OR operator
Class A contains a nonstatic void public function named functionA() that requires an integer argument. Class B derives from class A, and also contains a nonstatic void public function named functionA() that requires an integer argument. An object of class A can use _____.
. the class A version of the function
In C++, all false relational expressions are evaluated as _____________.
0
In C++, all false relational expressions have the mathematical value _____
0
What is the output produced by the following code? int x = 0; while(x < 7) cout << x << " "; ++x; cout << endl;
0 0 0 0 0 ...
If e and f are integers, and d = 16 and e = 17, then what is the value of d = = --e?
1
In C++, what is the result of 19 % 2?
1
If integers take four bytes of storage, then int days[31]; reserves _________ bytes of memory.
124
How many times does the loop body in the following code execute? for(int a = 0; a < 4; ++a) for(int b = 0; b < 4; ++b) cout << a << " " << b << " "; cout << endl;
16
In C++, what is the result of 5 + 4 * 3 + 2?
19
What is the output of the following code segment? int x = 20; int y = 1; if(x < 0 || x > y && y != 9 ) { --x; --y; } cout << x << " " << y << endl;
19 0
If you declare an array as int baskets[10] = {2,4,6};, then the value of baskets[0] is_____.
2
What is the output of the following code segment? int x = 3; int y = 6; if(x < 0 && y = 2) x = 40; cout << x << " " << y << endl;
3 6
. If you declare a variable as int var = 5; and the compiler stores var at memory address 3000, then the value of &var is ________.
3000
. If c is an integer, and c = 34, what is the value of ++c?
34
If a and b are integers, and a = 10 and b = 30, if you use the statement a += b, what is the resulting value of a?
40
What is the output of the following code segment? int x = 5; int y = 10; if(x < 0 || y < 0) x = 20; y = 35; cout << x << " " << y << endl;
5 35
What is the output of the following? int main() { cout << setw(2) << 5678; }
5678
How many times does the cout statement in the following code execute? int a = 2; int b = 6; while(a < 10) for(int b = 0; b < 4; ++b) { cout << a << " " << b << " "; ++a; } cout << endl;
8
What is the output produced by the following code? int total = 0; int a = 4; while(a < 6) { total += a; ++a; } cout << total << endl;
9
What is the output of the following? int main() { cout.precision(3); cout << 9.8765; }
9.88
A constructor is defined as LightBulb(int = 60);. The parameter is assigned to a field named watts. When you define an object as LightBulb oneBulb(90);, the watts variable will be set to ____________.
90
If you declare an array as int scores[100];, then the highest subscript you should use is _____.
99
Which of the following operators can be overloaded to be binary?
>
A throw most closely resembles _____.
A return
Paying attention to the important properties while ignoring unessential details is known as _____.
Abstraction
_____ refers to the order in which actions within an expression are carried out
Associativity
Arithmetic operations, such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%) that take two arguments use _____________ operators.
Binary
An expression that evaluates as true or false is known as a(n) ____________ expression.
Boolean
What is the output of this code segment? int age = 30; if(age = 40) cout << "Boy that is old!"; else cout << "Some day you will be old too";
Boy that is old!
What is the output of this code segment? int age = 40; if(age = 40) cout << "Boy that is old!"; else cout << "Some day you will be old too";
Boy that is old!
If you do not overload an = operator for a class _____.
C++ provides you with a built-in version
You create a class named Car with private non-static data fields named year, make, and price. The Car class contains a public non-static function named setYear() whose header is void Car::setYear(int year). Within this function, which statement correctly sets an object's field to the value of the parameter?
Car::year = year;
A translator that notes whether you have used a language correctly might be called a _____.
Compiler
If you create a structure named Dalmatian that has a public integer field named numSpots, then you can create an array of 101 Dalmatian objects with the statement:
Dalmatian litter[101];
Which type of statement does not occur in computer programs?
Denial
9. When you create a data structure or class object, you access the object's fields using the _____ operator.
Dot
True or False: . You could write an if-else statement that uses no semicolons between the location of the if and the location of the else.
False
True or False: A friend function can declare itself to be a friend of a class
False
True or False: A friend function can declare itself to be a friend of another function
False
True or False: An inner loop always repeats more times than an outer loop
False
True or False: An outer loop always repeats more times than an inner loop.
False
A constructor has been defined as FlowerSeed(int = 7);. Which of the following constructors could coexist with the defined constructor without any possible ambiguity?
FlowerSeed(int, double);
What is the output after executing the following segment of code? int num = 15; if(num > 20) cout << "Red" << endl; else if(num > 18) cout << "Yellow" << endl; else cout << "Green" << endl;
Green
The physical components of a computer system are called _____.
Hardware
The symbol used with the cout object << is called the _____ operator
Insertion
All of the following are C++ data types except _____.
Letter
Using a correctly written statement at the wrong time creates a(n) error _____.
Logical
What is output by the following code segment? int value = 12; value < 0? cout << "Yes" << endl : cout << "No" << endl;
No
What is the output after executing the following segment of code? int num = 10; if (num > 10) cout << "Yes" << endl; else cout << "No" << endl;
No
What is the output after executing the following segment of code? int num = 5; if (num > 10) cout << "Yes" << endl; cout << "No" << endl;
No
What is the output after executing the following segment of code? int num = 0; if(num > 1) { cout << "Yes" << endl; cout << "No" << endl; }
Nothing
. Assume a user runs a program containing the following code segment, and enters „k‟ at the prompt. What is the output? const char KINDERGARTEN_CODE = 'K'; cout << "Enter child's grade level "; cin >> gradeLevel; if(gradeLevel == KINDERGARTEN_CODE) cout << "Kindergarten student" << endl; else cout << "Older student" << endl;
Older student
To create an Order template class object named backOrder and assign 0 as the argument to the constructor, the proper syntax is _____.
Order backOrder(0);
All of the following are program control structures except _____.
Perpetuation
Object is to class as _____.
Plato is to philosopher
The feature that allows the same operations to be carried out differently depending on the context is _____.
Polymorphism
When a programmer determines the exact sequence in which events will take place, the program is said to be _____.
Procedural
Writing instructions that enable a computer to carry out a task or group of tasks is known as _____.
Programming
C++, Visual Basic, Java, and C# are all _____.
Programming languages
Another term for programs is _____.
Software
The rules of any programming language is ______?
Syntax
Which of the following is a legal constructor definition for a class named Table?
Table();
True or False: A child class can have multiple parents
True
True or False: A parent class can have multiple children
True
True or False: A single function can throw two different data types.
True
True or False: Any for statement can be rewritten as a while statement.
True
True or False: Any while statement can be rewritten as a for statement.
True
True or False: Most functions in classes are public.
True
True or False: Operators that are normally defined to be only unary must remain unary when you overload them
True
True or False: The first part of a for statement can be left empty
True
True or False: You cannont have a try without a catch
True
Writing two or more functions with the same name, but with different argument lists, is known as _____.
Writing two or more functions with the same name, but with different argument lists, is known as _____.
What is the output of the following? int main() { cout << "X"; cout.width(4); cout << 11; cout << 22 << "X"; }
X 11 22X
What is the output after executing the following segment of code? int num = 5; if(num < 4) cout << "Red" << endl; else if(num < 10) cout << "Yellow" << endl; else cout << "Green" << endl;
Yellow
What is output by the following code segment? int value = 5; value > 0? cout << "Yes" << endl : cout< "No" << endl;
Yes
. If you want to store an integer array named list at memory location 2000, you make the statement _____.
You cannot locate an array at a specific address like 2000
You try a function that throws three different types of exceptions and you want to ensure all are handled?
You must provide at least one catch block, but might provide more.
What does not an advantage of inheritance?
You save time because parent classes always provide more detail than child classes.
If you add a double, a float, and an int, the result is _____.
a double
A group of functions that generates from the same template is often called _____.
a family of functions
. An expression in which the operands have different data types is _____.
a mixed expression
What types of loops might the loop body never execute?
a while loop and a for loop
If you have correctly overloaded the * operator to multiply two members of the Furniture class, and you have declared two Furniture objects, aDesk and aChair, then which of the following is a legal expression?
aDesk * aChair
The Student class contains an overloaded addition operator which allows a number of credits to be added to a Student's totalCredits. The function header is Student Student::operator+(int newCredits). The = operator has not been overloaded. Which of the following is correct in a program that declares a Student object named aStudent?
aStudent = aStudent + 3;
C++ programmers refer to a type you define as an ADT, or an ______________.
abstract data type
The process of extracting the relevant attributes of an object is called __________.
abstraction
If either or both of the operands in addition, subtraction, multiplication, or division is a floating-point number, that is, a float or a double, then the result is _____.
always a floating-point number
. Addition, subtraction, multiplication, division, or modulus of any two integers _____.
always results in an integer
C++ uses the _____ as the address operator.
ampersand
An object is _____.
an instance of a class
Each link in a linked list is usually made up of _____.
an object and a pointer
. In C++ you can throw objects that are _____type.
any
In the template definition template, D stands for _____.
any class or type
A function template argument list can contain _____.
any combination of parameterized and nonparameterized types
Template functions can receive _____.
any number of parameters
A list of individual items that are stored in adjacent memory locations and all have the same type is called a(n) _____.
array
A template class is a class in which _____.
at least one type is parameterized
The primary reason you want to use #define, #ifndef, and #endif is to _____.
avoid declaring a class twice
Which is the correct order from largest to smallest? a. field, record, file b. file, record, field c. record, field, file d. field, file, record
b. file,record, field
Parent class is to child class as _____.
base class is to derived class
When you use the name of a function where you want it to execute within a program, you are __________ the function.
calling
Function templates _____.
can be overloaded
. Functions that contain no exception specification list _____.
can throw string messages can throw anything might throw nothing
When you call a public static function from outside its class, you _____.
can use an object
. A catch block _____.
can use any parameter it receives
A local variable is one that __________.
ceases to exist when its block ends
A derived class also can be called a _____class
child
To indicate that class X is a child of class Y, and that inheritance is public, the class definition is _____.
class X : public Y
A program that uses a class is known as the class's ______________.
client
You can use the switch statement to _____.
compare a single expression to several cases
A _____ is called automatically each time an object is created.
constructor
A template class that has been written to perform common class tasks, such as linking lists or sorting, is a(n) _____ class.
container
When a try block contains a function that might throw an exception, but no exception is thrown, then the program _____.
continues without incident
A variable that determines whether a loop body will execute is the loop _____ variable
control
The measure of the strength of the connection between two functions is called _____.
coupling
If you create a structure named Luggage and an object named myBlueOvernightBag, which of the following could output your overnight bag's price?
cout << myBlueOvernightBag.price;
. If you create a structure named Dalmatian that has a public integer field named numSpots, and you create an array of 101 Dalmatians named litter, then you can display the number of spots belonging to the first Dalmatian with the statement _____.
cout<<litter[0].numSpots;
Which of the following is a legal example of the way overloading is used in C++?
creating two constructors for a class
The most common arrangement for a class is that ______________.
data members are not public and functions are
You create a class in two sections called ______________.
declaration and implementation
A constructor that requires no arguments is an example of a _____ constructor.
default
If you know you need to execute a loop exactly 100 times, then it is a(n) _____ loop.
definite
When an object goes out of scope, a(n) _____ is called automatically.
destructor
A general principle of object-oriented error handling is that a function that might cause an exception should _____.
detect an exception but not handle it
Which of the following is not a classification of class member functions?
detective functions
. The advantage to creating container classes is that _____.
development time for future classes is reduced
Which of the following is a posttest loop?
do-while loop
. Class A has a protected field named fieldA. When a class B is derived from class A, and C is derived from class B, then you know that class C _____
does not have more liberal access to fieldA than class B does
Which of the following is a valid prototype for a function that accepts an integer argument and returns a double value?
double function (int);
Which of the following is equivalent to double money = 4.56;?
double money(4.56);
Which of the following is a manipulator?
endl
A catch block contains _____ parameter(s).
exactly
Errors that occur during a program's execution are called _____.
exceptions
The C++ operator used for input with cin is called the _____ operator
extraction
Random file processing is more efficient than sequential file processing when _____.
few records within a file will be processed
The primary reason you use an exception specification is _____.
for documentation
The arguments such as ios::showpoint that determine the state of the cout object are called _____.
format flags
Another term for parameterized is _____.
generic
The data entry function that leaves unused characters in the input stream is _____.
get()
A variable that is known to all functions within a file is said to be__________ .
global
When you encapsulate class components, you ______________ them.
hide
The best functions have _____.
high cohesion and loose coupling
Multiplication, division, and modulus are said to have ___ than addition and subtraction.
higher arithmetic precedence
The compiler determines the parameterized type in a function template _____.
implicitly
If a field named someField is private in the parent class, and a child class inherits with public access, then within the child class someField is _____.
inaccessible
You can define a function by __________.
including the function's filename at the top of the file that uses it
You use a subscript to _____.
indicate a position within an array
The principle that knowledge of a general category can be applied to more specific objects is _____.
inheritance
The most common use of constructors is to _____.
initialize data fields
A loop control variable should almost always be used three times in these ways:
initialize, compare, alter
Which of the following correctly declares a reference for int myCreditHours;?
int &cr = myCreditHours;
You should use an inline function when __________.
it is called infrequently
The Standard Template Library contains all of the following _____.
iterators containers algorithms
. Assume k and m are integers and that k = 5 and m = 7. Which of the following results in a change in the value of m?
k = m++;
The C++ Standard library contains an exception class an already derived subclasses that include _____.
logic_error and runtime_error
You use a _____ to create a compound Boolean expression in which two conditions must be true for the entire expression to evaluate as true.
logical AND
You use a _____ to create a compound Boolean expression in which only one of two conditions needs to be true for the entire expression to evaluate as true.
logical OR
When you overload the << operator to work with an object, you must _____.
make the operator function a friend function
. If a member of a base class named Base is protected, then it can be used by functions that are _____.
members of Base members of children of Base
A program _____ throw an exception from a function named within a try block.
might
. Consider a structure named Rug that contains two integer fields, length and width. Assume you have declared a Rug named myBedroomCarpet. Which of the following is legal?
myBedroomCarpet.width = 10;
Which of the following does not have the same result as myValue = myValue + 1?
myValue = 1;
When a loop is contained within another, the loops are _____.
nested
When an if statement occurs within either the if or else clause of another if statement, it is known as a _____ if.
nested
When you pass a reference to a function, the function can alter the variable if the reference is __________.
not constant
What is the output produced by the following code? int x = 0; while(x < 7); { cout << x << " "; ++x; }
nothing
If you create a character array using the statement char name[] = "Paulette"; then the created string ends with a(n) _____.
null character
When you create an object with the following statement, then what is the output file object within the program? ofstream oFile("c:\\data\\document"); .
oFile
In C++, cout and cin are _____.
objects
Object-oriented programmers primarily focus on _____.
objects and the tasks that must be performed with those objects
A single-alternative selection is one in which an action takes place _____.
only when the result of the decision is true
Applying operators to your own abstract data types is called _____ overloading.
operator
Whenever a class contains two constructors, the constructors are _____.
overloaded
Using the same function name with different argument lists is called __________ functions
overloading
When you want to override one of four constructor default values for an object you are instantiating, you also must _____.
override all parameters to the left of the one you want to override
Within a block or function, a local variable __________ a global one
overrides
The difference between the function prototypes for the overloaded prefix and postfix ++ for any class is the _____.
parameter list
In a C++ program, all function names are always followed by a pair of __________.
parentheses
Because + can be used to mean addition as well as a positive value, the + operator is said to be _____.
polymorphic
The built-in * operator is _____________.
polymorphic
The feature in object-oriented programs that allows the same operation to be carried out differently, depending on the object, is _____
polymorphism
. If you declare an array as double prices[10];, then the expression &prices[2] has the same meaning as the expression _____.
prices + 2
A technique that programmers use to provide object encapsulation is to usually make objects' data ______________.
private
If a field named someField is public in the parent class, and a child class inherits with private access, then within the child class someField is _____.
private
If a field named someField is public in the parent class, and a child class inherits with protected access, then within the child class someField is _____
protected
The word interface is most closely associated with ______________.
prototypes of public functions in classes
If you declare an integer pointer as int *pt; and you declare an integer variable as int num; , then which of the following is legal?
pt = #
The most commonly used inheritance access specifier is _____
public
A function that has been declared to be a friend of a class has access to the ___________ data in the class
public private
To be able to add three or more objects in sequence, as in x + y + z, you must overload the + operator to _____.
return an object of the same type as the parameters
Both a function header and its prototype contain _________.
return types
. The term C++ programmers use for the extent to which a variable is known is __________.
scope
The operator you use in a function header that ties a function name to a class is the ______________ operator.
scope resolution
A value that you use as input to stop a loop from continuing to execute is commonly called a(n) ____________ value.
sentinel
You use the ignore() function to _____.
skip any characters left in the input stream after a call to get()
If a file named someFile is opened successfully, which of the following is evaluated as true?
someFile.good()
To create just one memory location for a field no matter how many objects you instantiate, you should declare the field to be ______________.
static
A sequence of bytes used to perform input and output operations is a _____.
stream
A C++ value expressed within double quotation marks is commonly called a _____.
string
The get() function _____
takes a reference to a char as an argument and returns a reference to the istream class
Which English-language example best represents polymorphism?
taking a nap as opposed to taking a bribe killing time as opposed to killing a bug ordering a pizza as opposed to ordering a soldier
Which of the following is a template definition?
template
If an exception is thrown from a try block and no catch block exists with a matching parameter type, then the program _____.
terminates
In a while loop, _____.
the Boolean expression is always evaluated at least once
If you declare an array as double money[4];, then &money[2] represents _____.
the address of the third element in the array
. In C++, the & operator in front of a variable represents _____.
the address of the variable
When you call an ofstream constructor and use a filename as an argument, then _____.
the constructor creates and opens the file
When you include two catch blocks in a program, and a thrown object can be accepted by either of them, _____.
the first catch block will execute
When a function template has two parameterized types, one as the return value, and one as an argument, then _____.
the first type must be explicitly coded
Which of the following is an advantage of passing an address of a variable to a function?
the function can alter the original variable in the calling function
The primary advantage to overloading >> and << to use with objects is _____.
the program code that uses the functions contains syntax that is easy to understand
If you declare an array as int numbers[10];, then number[1] represents _____.
the second element in the array
An initialization list used in the prototype for a constructor provides _____.
the types and names of arguments required by a constructor
The pointer that is automatically supplied when you call a non-static class member function is the ______________ pointer
this
Within its parentheses, the for loop contains _____ parts that are separated by semicolons
three
When a function sends an error message to the calling function, the function is said to _____ an exception.
throw
You explicitly name a type in a function template call ____.
to override an implicit type
Data is stored in binary format for all of the following reasons except _____.
to prevent unauthorized file copying
If you declare an array as int homeRuns[7];, then the value of homeRuns[0] is _____.
unknown
. If you declare an array as int vals[5];, then you can double the value stored in vals[2] with the statement _____.
vals[2] *= 2;
In different programming languages, program modules are known as all of the following except __________.
variables
A class named Apartment contains a non-static public function named showRent() that neither takes nor receives arguments. The correct function header for the showRent() function is ______________.
void Apartment::showRent()
Which of the following functions could coexist in a program with void function(double, int); with no ambiguity possible?
void function (double);
Which of the following are inherited?
void functions
You control how data is stored in classes by using ______________.
well-written public functions
When you use any descendent of the built-in exception class, you inherit a function named _____ that returns an exception object's error message.
what()
The getline() function reads a line of text until it reaches _____.
whichever come first: the length used as the second argument or the character used as the third argument
Which of the following is not a manipulator?
width
Creating a function template is most appropriate when _____.
you are writing several functions that take different argument types, but use the same logic
The primary advantage to overloading functions is _____________.
you can use one function name for similar operations, regardless of the data types involved
Which is a legal destructor for the Game class?
~Game();