C++ Exam'

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

When you overload the operator() function for a class, the parameter is required to be an integer. A. True B. False

B. False

____ is a string constant. A. 'H' B. '\n' C. "Hello" D. Hello

C. "Hello"

The ____ operator is a unary operator. A. >> B. % C. & D. /

C. &

The result of evaluating 3.0 / 4 + 2.2 is ____. A. 2 B. 2.2 C. 2.95 D. 2.99

C. 2.95

The segment of code shown below displays "Hello!" ____ times: int count; const int NUM_LOOPS = 5;count = 0; while( count < NUM_LOOPS){ cout<<++count; } A. 0 B. 4 C. 5 D. 6

C. 5

Which of the following operators has the highest precedence? A. new B. % C. :: D. ||

C. ::

When does the following code display "Yes"?if(department == 1 || 2)cout<<"Yes"; A. When department is 1 B. When department is 1 or 2 C. Always D. Never

C. Always

getName() is a typical example of a(n) ____ function. A. manager B. auxiliary C. inspector D. predicate

C. inspector

If the expression in the while statement is true, the ____executes, and the Boolean expression is tested again. A. conditional expression B. iterator C. loop body D. inner loop

C. loop body

When a class serves as a base class to other classes, all of its members are included when you create an object from a derived class. However, the members of the base class that are ____ are not directly accessible from within the child class functions. A. public B. protected C. private D. virtual

C. private

A ____ function has the same name as its class. A. constructor B. manager C. predicate D. mutator

A. constructor

The initialize portion of a for loop comes after the evaluate portion. A. True B. False

B. False

The value of a static field cannot be changed. A. True B. False

B. False

Several destructors can exist for each class. A. True B. False

B. False

The unary operator ____ is the not operator; it means "the opposite of," and essentially reverses the true/false value of an expression. A. ! B. & C. % D. $

A. !

____ cohesion occurs when all of the function operations contribute to the performance of only one task. A. Functional B. Procedural C. Complete D. Default

A. Functional

A derived class is also called a subclass or descendant. A. True B. False

A. True

The ____ takes one action when its Boolean expression is evaluated as true, and uses an else clause to define the actions to take when the expression is evaluated as false. A. dual-alternative if B. single-alternative if C. switch statement D. conditional operator

A. dual-alternative if

A loop that falls entirely within the body of another is a(n) ____ loop. A. inner B. child C. restricted D. connected

A. inner

The C++ modulus operator is ____. A. & B. # C. ! D. %

D. %

Which of the following operators has the lowest precedence? A. new B. && C. :: D. .

B. &&

When you want to use a value stored in a pointer, you must use the ____ to dereference the pointer, or use the value to which it points. A. ampersand B. asterisk C. pipe D. bang

B. asterisk

The body of a do-while loop executes ____. A. zero or more times B. at least one time C. at most one time D. any number of times

B. at least one time

sortAscending() is a typical example of a(n) ____ function. A. manager B. auxiliary C. inspector D. predicate

B. auxiliary

You ____ assign a value to a field in a class definition. A. can B. cannot C. should D. should not

B. cannot

To ____ a value is to transform it to another data type. A. reduce B. cast C. convert D. unify

B. cast

The expression cout << (9 > 2); yields ____ as output. A. 0 B. 1 C. true D. false

B. 1

The result of evaluating 3 / 4 + 2.2 is ____. A. 2 B. 2.2 C. 2.95 D. 2.99

B. 2.2

The scope resolution operator is ____. A. & B. :: C. * D. ->

B. ::

An initialization list is the part of the constructor header to the left of the colon. A. True B. False

B. False

Encapsulation simplifies your concept of the process or object, allowing you to ignore nonessential details. A. True B. False

B. False

Finding syntax errors is much more time consuming for a programmer than finding logical errors. A. True B. False

B. False

In template <class T> stands for a programmer created class. A. True B. False

B. False

The =operator() function overloads the assignment operator. A. True B. False

B. False

When you create a class, you usually make data items public. A. True B. False

B. False

____ I/O is formatted; that is, bytes are grouped into meaningful units such as integers, doubles, and class object types. A. Low-level B. High-Level C. Primitive D. Advanced

B. High-Level

____ variables are known only in a limited scope. A. Global B. Local C. Limited D. Modular

B. Local

____ arrays are corresponding arrays in which values in the same relative locations are logically related. A. Two-dimensional B. Parallel C. One-dimensional D. Structured

B. Parallel

A(n) ____ is the expression used within the parentheses when you call a function. A. value B. argument C. input D. prototype

B. argument

When you declare a pointer, you insert a(n) ____ in front of the variable name. A. ampersand B. asterisk C. pipe D. pound sign

B. asterisk

The statement that executes a function is the function ____. A. statement B. alias C. call D. expression

C. call

A ____ consists of a number of data fields that are logically connected because they pertain to the same entity. A. data field B. data hierarchy C. data record D. data file

C. data record

The ____ section of a class contains the class name, variables (attributes), and function prototypes. A. header B. definition C. declaration D. implementation

C. declaration

A ____ loop is one that must execute a specific number of times. A. while B. do-while C. definite D. count-controlled

C. definite

To create a loop that executes at least one time, you should use a ____ loop. A. for B. while C. do-while D. pretest

C. do-while

A(n) ____ language is one to which you can add your own data types. A. low-level B. high-level C. extensible D. object-oriented

C. extensible

The ____ function takes arguments that set the bits of cout; that is, the arguments turn the bits in the format flag on. A. setw() B. setprecision() C. setf() D. unsetf()

C. setf()

A ____ class member exists, even when you have not instantiated any objects of the class. A. public B. private C. static D. const

C. static

To create a function template that employs multiple generic types, you simply use a(n) ____ for each type. A. #include statement B. function prototype C. unique type identifier D. separate template class

C. unique type identifier

The C++ directive ____ allows you to test whether a class has already been defined in a project; it means "if not defined." A. #define B. #endif C. #ifdef D. #ifndef

D. #ifndef

You can use the address operator (____) to examine the memory address of a variable. A. % B. $ C. * D. &

D. &

Consider the following C++ code: if(driverAge < 26)premiumDue += 100; if(driverAge > 50)premiumDue -= 50; if(numTickets == 2)premiumDue += 60.25; How much is added to premiumDue if driverAge is 22and numTickets is 0? A. -50 B. 10.25 C. 60.25 D. 100

D. 100

____ is not a valid operator in C++. A. & B. %= C. ++ D. =+

D. =+

Consider the following segment of code: if(vacationDays = 0)cout << "No vacation days available" << endl; else cout << "You have vacation days coming" << endl; What error can you identify? A. The code assumes indentation has a logical purpose. B. A semicolon is incorrectly inserted. C. There are no curly braces. D. An assignment operator is used in a comparison.

D. An assignment operator is used in a comparison.

____ is a measure of the strength of the connection between two functions; it expresses the extent to which information is exchanged by functions. A. Encapsulation B. Abstraction C. Cohesion D. Coupling

D. Coupling

Multiplication, division, and modulus are said to have higher ____ than addition or subtraction. A. priority B. unifying factor C. cast value D. arithmetic precedence

D. arithmetic precedence

Characters may be stored in character data type variables, declared with the keyword ____. A. character B. String C. Char D. char

D. char

The ____ of a variable defines what kind of values may be stored in a variable and what kind of operations can be performed on it. A. syntax B. language C. input D. data type

D. data type

A(n) ____ mode indicates how a file is opened—for example, for input or output. A. I/O B. precision C. stream D. file

D. file

A ____ function cannot be inherited. A. virtual B. friend C. public D. protected

B. friend

The ____ operator is a binary operator. A. ~ B. % C. ->* D. !

B. %

____ is an example of overloading the postfix increment operator. A. Inventory& operator++(int); B. Inventory& operator++(); C. Inventory& ++operator(int); D. Inventory& ++operator();

A. Inventory& operator++(int);

What common pitfall can you identify in the following segment of code? int number; while(number <= 10){ cout<<++number; } A. The programmer failed to initialize the loop control variable. B. An unwanted semicolon was added. C. The programmer forgot the curly braces. D. It assumes C++ is case sensitive.

A. The programmer failed to initialize the loop control variable.

All modern programming languages require that variable names be one word; that is, they cannot include any embedded spaces. A. True B. False

A. True

Almost every C++ expression has a numeric value, and any C++ expression can be evaluated as part of an if statement. A. True B. False

A. True

C++ programmers do not refer to an array of characters as a string unless the last usable character in the string is the null character. A. True B. False

A. True

Format flags are also known as state flags. A. True B. False

A. True

If a program runs for several seconds and appears to be doing nothing or produces repeated output, you should suspect an infinite loop. A. True B. False

A. True

In C++, any value other than 0, even a negative value, is considered to be true. A. True B. False

A. True

No matter which access specifier you use when creating a child class, access to parent class members never becomes more lenient than originally coded. A. True B. False

A. True

Statements that can never execute are called dead code. A. True B. False

A. True

Temporary data storage exists in computer memory; it is lost when power is lost. A. True B. False

A. True

The modulus operator gives the remainder of integer division; it can be used only with integers. A. True B. False

A. True

When more than one arithmetic operator is included in an expression, then multiplication, division, and modulus operations always occur before addition or subtraction. A. True B. False

A. True

When you assign one pointer to another, you are not making a copy of the data; instead, you are setting two pointers to point to the same memory location. A. True B. False

A. True

You can use multiple explicit types when you call a template function. A. True B. False

A. True

Many of the constructor complications that occur when inheriting from multiple classes are minimized if you always include ____. A. a default constructor for every class B. the virtual keyword when declaring the parent class C. a friend function D. an specialized destructor

A. a default constructor for every class

To use the function displayStudentData() of the object aSophmore that belongs to the class Student, the correct syntax is ____. A. aSophmore.displayStudentData(); B. Student.displayStudentData(); C. aSophmore::displayStudentData(); D. *aSophmore.displayStudentData();

A. aSophmore.displayStudentData();

When two operations with the same precedence appear in an arithmetic expression, the operations are carried out in order from either left to right or right to left based on their ____. A. associativity B. precedence C. unifying factor D. modulus

A. associativity

To indicate that a variable is a pointer, you should begin the variable's name with a(n) ____. A. asterisk B. ampersand C. pipe D. exclamation point

A. asterisk

Function templates ____ support multiple parameters. A. can B. cannot C. sometimes D. should not

A. can

An integer value may be stored in an integer data type variable, declared with the keyword ____. A. int B. integer C. INT D. Integer

A. int

In C++, you use the ____ operator to dynamically allocate memory. A. new B. ++ C. += D. create

A. new

The while loop and the for loop are ____ loops. A. pretest B. posttest C. nested D. inner

A. pretest

C++ programmers usually use the ____ access specifier for inheritance. A. public B. protected C. private D. friend

A. public

____ data and functions can be accessed anywhere the class is in scope. A. public B. protected C. private D. virtual

A. public

The statement return letter;can be alternatively written as ____. Both statements work identically. A. return(letter); B. return:letter; C. return{letter}; D. returnletter;

A. return(letter);

A C++ value expressed within double quotation marks is commonly called a ____. A. string B. character C. quote D. citation

A. string

The rules of any language make up its ____. A. syntax B. vocabulary C. grammar D. parser

A. syntax

When you instantiate a class object that has been derived from another class, ____. A. the constructor for the base class is called first, followed by the derived class constructor B. the constructor for the derived class is called first, followed by the base class constructor C. only the constructor for the derived class is called D. only the constructor for the base class is called

A. the constructor for the base class is called first, followed by the derived class constructor

The ____ pointer is automatically supplied every time you call a non-static member function of a class. A. this B. super C. const D. void

A. this

When you mix data types in a binary arithmetic expression, the values on each side of the arithmetic operator are temporarily converted to a ____ type—the data type of the value that occupies more memory and to which all the types in the expression are converted. A. unifying B. standard C. common D. large

A. unifying

Complete the following program, which displays all the values in the array: const int SZ_OF_ARRAY = 5; int arrayInt[SZ_OF_ARRAY] = {34, 56, 12, 3, 99}; for(int x = 0; ____ ; ++x) cout << arrayInt[x] << endl; A. x < SZ_OF_ARRAY B. x <= SZ_OF_ARRAY C. x < size(arrayInt) D. x <= sizeof(arrayInt)

A. x < SZ_OF_ARRAY

Consider the following segment of code: char genderCode; cout << "Enter F for female or M for male ";cin >> genderCode; if(genderCode == 'F')cout << "Female" << endl; else if(genderCode == 'M') cout << "Male" << endl; else cout << "Invalid code" << endl; What will appear on the screen if the user enters 'M'? A. "Female" B. "Male" C. "Invalid code" D. ""

B. "Male"

The ____ directive means that you have reached the end of the block of code that you are defining. A. #define B. #endif C. #ifdef D. #ifndef

B. #endif

Which of the following statements produces the same output as cout<<(someNumbers+1);? Assume someNumbers is an array of integers. A. cout << &someNumbers[0]; B. cout << &someNumbers[1]; C. cout << someNumbers[0]; D. cout << someNumbers[1];

B. cout << &someNumbers[1];

A(n) ____ parameter to a function is one for which an automatic value is supplied if you do not explicitly use one. A. implicit B. default C. local D. global

B. default

Programmers sometimes refer to ____ as an example of using a "black box." A. polymorphism B. encapsulation C. instantiation D. abstraction

B. encapsulation

The ____ is a key combination that indicates completion of data entry. A. delimiting character B. end-of-file indicator C. data record D. setiosflags

B. end-of-file indicator

In the following segment of code, number = 1 while(number <= 10); { cout<<number<<endl; } the body of the loop is ____. A. empty B. everything in between the curly brackets C. cout<<number<<endl; D. number <= 10;

B. everything in between the curly brackets

C++ ____ you to use the built-in precedence rules for your class operators. A. encourages B. forces C. forbids D. enables

B. forces

A(n) ____ is one that can stand for any number of C++ types. A. abstract data type B. generic parameter C. structure D. container class

B. generic parameter

The ____ function skips any additional characters left in the input stream after data is accepted. A. open() B. ignore() C. unsetf() D. getline()

B. ignore()

In object-oriented programming, descendent classes can ____ all the attributes of the original (or parent) class, or they can override inappropriate attributes. A. extend B. inherit C. implement D. adopt

B. inherit

In C++, a(n) ____ comment begins with two slashes (//) and continues to the end of the line on which it is placed. A. block B. line C. standard D. expanded

B. line

The do-while loop is a(n) ____ loop. A. pretest B. posttest C. nested D. inner

B. posttest

The ____ of a variable defines where it can be accessed in a program. A. abstraction B. scope C. encapsulation D. lifetime

B. scope

A struct definition always ends with a(n) ____ following the closing curly brace. A. colon B. semicolon C. ampersand D. square bracket

B. semicolon

The only type of class member function that does not have a this pointer is a ____ member function. A. const B. static C. public D. private

B. static

The ____, although not as flexible as the if statement, is useful when a single variable must be compared to multiple values. A. else statement B. switch statement C. case statement D. conditional operator (?)

B. switch statement

Complete the following function template:____ T reverse(T x){ return -x; } A. template : class T B. template <class T> C. template (class T) D. template {class T}

B. template <class T>

The ____ function reads a line of text at the address represented by the first argument to the function until it reaches either the length used as the second argument or the character used as the third argument. A. open() B. ignore() C. get() D. getline()

D. getline()

A ____ repeats actions while some condition remains unchanged. A. sequence structure B. selection structure C. control structure D. loop structure

D. loop structure

The name of the function that overloads the + symbol is the ____ function. A. op+() B. +() C. +operator() D. operator+()

D. operator+()

A loop that completely contains another is a(n) ____ loop. A. protecting B. parent C. covering D. outer

D. outer

Any child class function with the same name and argument list as the parent ____ the parent function. A. specializes B. generalizes C. overloads D. overrides

D. overrides

Any child class function with the same name as the parent, yet with an argument list that differs from the parent's, ____ the parent function. A. specializes B. generalizes C. overloads D. overrides

D. overrides

All precedence rules can be overridden with appropriately placed ____. A. colons B. semicolons C. casts D. parentheses

D. parentheses

Suppose you create a structure that has an integer field called partNum; Next, you create an array of ten elements of objects of this structure. Which of the following is a correct way to access the first element of the array? A. (part.partNum)[0] B. part.partNum[0] C. part.[0]partNum D. part[0].partNum

D. part[0].partNum

isUpper() is a typical example of a(n) ____ function. A. manager B. auxiliary C. defining D. predicate

D. predicate

The ____ function can be used to deselect a bit in the format flag. A. setw() B. setprecision() C. setf() D. unsetf()

D. unsetf()

A Boolean data type variable can be declared using the ____ data type, which has only two possible values—true or false. A. boolean B. bool C. logical D. flag

b. bool


Set pelajaran terkait

Project Management Vocabulary 1 & 2

View Set

Bio 412 exam 1--> Quiz questions

View Set

Methods of data collection and analysis

View Set