Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Exam// Questions with answers/ latest updated study guide / 100% guaranteed pass, Exams of C programming

C++ Exam// Questions with answers/ latest updated study guide / 100% guaranteed pass

Typology: Exams

2023/2024

Available from 11/12/2024

wil-mug
wil-mug 🇰🇪

5

(3)

1.3K documents

1 / 55

Toggle sidebar

Related documents


Partial preview of the text

Download C++ Exam// Questions with answers/ latest updated study guide / 100% guaranteed pass and more Exams C programming in PDF only on Docsity!

C++ Exam// Questions with answers/ latest

updated study guide / 100% guaranteed pass

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 - ANSWER b. bool Characters may be stored in character data type variables, declared with the keyword ____. A. character B. String C. Char D. char - ANSWER D. char A ____ repeats actions while some condition remains unchanged. A. sequence structure B. selection structure C. control structure D. loop structure - ANSWER D. loop structure 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 - ANSWER B. inherit 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 - ANSWER D. data type An integer value may be stored in an integer data type variable, declared with the keyword ____. A. int B. integer C. INT D. Integer - ANSWER A. int The rules of any language make up its ____. A. syntax B. vocabulary C. grammar D. parser - ANSWER A. syntax 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 - ANSWER B. line Finding syntax errors is much more time consuming for a programmer than finding logical errors. A. True B. False - ANSWER B. False All modern programming languages require that variable names be one word; that is, they cannot include any embedded spaces. A. True B. False - ANSWER A. True A ____ function cannot be inherited. A. virtual B. friend C. public D. protected - ANSWER B. friend 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 - ANSWER D. overrides ____ data and functions can be accessed anywhere the class is in scope. A. public B. protected C. private D. virtual - ANSWER A. public

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 - ANSWER A. the constructor for the base class is called first, followed by the derived class constructor 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 - ANSWER D. overrides C++ programmers usually use the ____ access specifier for inheritance. A. public B. protected C. private D. friend - ANSWER A. public 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 - ANSWER A. a default constructor for every class 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 - ANSWER C. private A derived class is also called a subclass or descendant. A. True B. False - ANSWER 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 - ANSWER A. True Function templates ____ support multiple parameters. A. can B. cannot C. sometimes D. should not - ANSWER A. can Complete the following function template:____ T reverse(T x){ return - x; } A. template : class T B. template C. template (class T) D. template {class T} - ANSWER B. template

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 - ANSWER C. unique type identifier 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 - ANSWER B. generic parameter In template stands for a programmer created class. A. True B. False - ANSWER B. False You can use multiple explicit types when you call a template function. A. True B. False - ANSWER A. True 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() - ANSWER C. setf() 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 - ANSWER C. data record 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() - ANSWER D. getline() The ____ function can be used to deselect a bit in the format flag. A. setw() B. setprecision() C. setf() D. unsetf() - ANSWER D. unsetf() A(n) ____ mode indicates how a file is opened—for example, for input or output. A. I/O B. precision C. stream D. file - ANSWER D. file ____ 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 - ANSWER B. High-Level The ____ function skips any additional characters left in the input stream after data is accepted. A. open() B. ignore() C. unsetf() D. getline() - ANSWER B. ignore() The ____ is a key combination that indicates completion of data entry. A. delimiting character B. end-of-file indicator C. data record D. setiosflags - ANSWER B. end-of-file indicator Temporary data storage exists in computer memory; it is lost when power is lost. A. True B. False - ANSWER A. True Format flags are also known as state flags. A. True B. False - ANSWER A. True To ____ a value is to transform it to another data type. A. reduce B. cast C. convert D. unify - ANSWER B. cast

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. $ - ANSWER A.! ____ is not a valid operator in C++. A. & B. %= C. ++ D. =+ - ANSWER D. =+ 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 - ANSWER A. associativity All precedence rules can be overridden with appropriately placed ____. A. colons B. semicolons C. casts D. parentheses - ANSWER D. parentheses 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 - ANSWER A. unifying The C++ modulus operator is ____. A. & B. # C.! D. % - ANSWER D. % Multiplication, division, and modulus are said to have higher ____ than addition or subtraction. A. priority B. unifying factor C. cast value D. arithmetic precedence - ANSWER D. arithmetic precedence The modulus operator gives the remainder of integer division; it can be used only with integers. A. True B. False - ANSWER 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 - ANSWER A. True The result of evaluating 3.0 / 4 + 2.2 is ____. A. 2 B. 2. C. 2.

D. 2.99 - ANSWER C. 2.

The expression cout << (9 > 2); yields ____ as output. A. 0 B. 1 C. true D. false - ANSWER B. 1 The result of evaluating 3 / 4 + 2.2 is ____. A. 2 B. 2. C. 2. D. 2.99 - ANSWER B. 2. A struct definition always ends with a(n) ____ following the closing curly brace. A. colon B. semicolon C. ampersand D. square bracket - ANSWER B. semicolon 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 - ANSWER A. dual-alternative if 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 (?) - ANSWER B. switch statement In C++, any value other than 0, even a negative value, is considered to be true. A. True B. False - ANSWER 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 - ANSWER A. True 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 - ANSWER C. Always 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. "" - ANSWER B. "Male" 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. - ANSWER D. An assignment operator is used in a comparison. 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. C. 60. D. 100 - ANSWER D. 100 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 - ANSWER B. at least one time To create a loop that executes at least one time, you should use a ____ loop. A. for B. while C. do-while D. pretest - ANSWER C. do-while A loop that completely contains another is a(n) ____ loop. A. protecting B. parent C. covering D. outer - ANSWER D. outer 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 - ANSWER C. loop body The do-while loop is a(n) ____ loop. A. pretest B. posttest C. nested D. inner - ANSWER B. posttest A ____ loop is one that must execute a specific number of times.

A. while B. do-while C. definite D. count-controlled - ANSWER C. definite The while loop and the for loop are ____ loops. A. pretest B. posttest C. nested D. inner - ANSWER A. pretest A loop that falls entirely within the body of another is a(n) ____ loop. A. inner B. child C. restricted D. connected - ANSWER A. inner 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 - ANSWER A. True The initialize portion of a for loop comes after the evaluate portion. A. True B. False - ANSWER B. False 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 - ANSWER C. 5 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. - ANSWER A. The programmer failed to initialize the loop control variable. 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; - ANSWER B. everything in between the curly brackets

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) - ANSWER A. x < SZ_OF_ARRAY A C++ value expressed within double quotation marks is commonly called a ____. A. string B. character C. quote D. citation - ANSWER A. string 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 - ANSWER A. asterisk 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]; - ANSWER B. cout << &someNumbers[1];

____ is a string constant. A. 'H' B. '\n' C. "Hello" D. Hello - ANSWER C. "Hello" You can use the address operator (____) to examine the memory address of a variable. A. % B. $ C. * D. & - ANSWER D. & ____ 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 - ANSWER B. Parallel 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 - ANSWER D. part[0].partNum 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 - ANSWER 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 - ANSWER A. True When you declare a pointer, you insert a(n) ____ in front of the variable name. A. ampersand B. asterisk C. pipe D. pound sign - ANSWER B. asterisk The ____ of a variable defines where it can be accessed in a program. A. abstraction B. scope C. encapsulation D. lifetime - ANSWER B. scope A(n) ____ is the expression used within the parentheses when you call a function. A. value B. argument C. input D. prototype - ANSWER B. argument 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 - ANSWER B. default ____ variables are known only in a limited scope. A. Global B. Local C. Limited D. Modular - ANSWER B. Local The statement that executes a function is the function ____. A. statement B. alias C. call D. expression - ANSWER C. call The statement return letter;can be alternatively written as ____. Both statements work identically. A. return(letter); B. return:letter; C. return{letter}; D. returnletter; - ANSWER A. return(letter); 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 - ANSWER B. asterisk Statements that can never execute are called dead code. A. True

B. False - ANSWER A. True Encapsulation simplifies your concept of the process or object, allowing you to ignore nonessential details. A. True B. False - ANSWER B. False 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 - ANSWER C. extensible You ____ assign a value to a field in a class definition. A. can B. cannot C. should D. should not - ANSWER B. cannot 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 - ANSWER B. static The ____ section of a class contains the class name, variables (attributes), and function prototypes. A. header B. definition C. declaration

D. implementation - ANSWER C. declaration A ____ class member exists, even when you have not instantiated any objects of the class. A. public B. private C. static D. const - ANSWER C. static The scope resolution operator is ____. A. & B. :: C. * D. - > - ANSWER B. :: Programmers sometimes refer to ____ as an example of using a "black box." A. polymorphism B. encapsulation C. instantiation D. abstraction - ANSWER B. encapsulation 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 - ANSWER A. this When you create a class, you usually make data items public. A. True B. False - ANSWER B. False

The value of a static field cannot be changed. A. True B. False - ANSWER B. False 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(); - ANSWER A. aSophmore.displayStudentData(); getName() is a typical example of a(n) ____ function. A. manager B. auxiliary C. inspector D. predicate - ANSWER C. inspector A ____ function has the same name as its class. A. constructor B. manager C. predicate D. mutator - ANSWER A. constructor ____ 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 - ANSWER D. Coupling sortAscending() is a typical example of a(n) ____ function. A. manager B. auxiliary C. inspector D. predicate - ANSWER B. auxiliary 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 - ANSWER D. #ifndef ____ cohesion occurs when all of the function operations contribute to the performance of only one task. A. Functional B. Procedural C. Complete D. Default - ANSWER A. Functional isUpper() is a typical example of a(n) ____ function. A. manager B. auxiliary C. defining D. predicate - ANSWER D. predicate 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 - ANSWER B. #endif An initialization list is the part of the constructor header to the left of the colon. A. True B. False - ANSWER B. False Several destructors can exist for each class. A. True B. False - ANSWER B. False The ____ operator is a unary operator. A. >> B. % C. & D. / - ANSWER C. & The ____ operator is a binary operator. A. ~ B. % C. - >* D.! - ANSWER B. % Which of the following operators has the highest precedence? A. new B. % C. ::