Programming Fundamentals II midterm (Chapters 8 through 11)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

toupper and tolower require the _______ header file.

<cctype> header file.

atoi, atol, and atof all require the ________ header file.

<ctsdlib> header file.

Smart pointers require the __________ header file.

<memory> header file.

The number of comparisons made by a binary search is expressed in powers of two. (T/F)

True

Aggregation

When a class contains an instance of another class.

What is the value stored in num after the following statement executes? num = atoi("1000"); A) 1000 B) 999 C) "1000" D) "1 thousand" E) None of these

A) 1000. Function atoi converts a string to an integer value, then returns it.

Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared. A) 20,000 B) only the first two C) only half D) 2,000 E) None of these

A) 20,000. A linear search would have to step through all the values before it would finally find the value it was searching for.

The function that accepts a C-string as an argument and converts the string to a long integer is A) atol B) strlong C) strtolong D) stringlong E) None of these

A) atol. This function accepts a C-string as an argument, and converts it to a long integer. None of the other choices are real.

When a structure is passed ________ to a function, its members are NOT copied. A) by reference B) by value C) Either of these D) Neither of these

A) by reference. If you pass a structure directly to a function, it must copy everything into it. If you pass by reference, then it does not copy the entire structure.

A class is a(n) ________ that is defined by the programmer. A) data type B) function C) method D) attribute E) None of these

A) data type

The process of object-oriented analysis can be viewed as the following steps: A) identify objects, then define each object's attributes, behaviors, and relationships B) define data members and member functions, then assign the class name C) declare public and private variables, prototype functions, and then write code D) write the main() function, then determine which classes are needed E) None of these

A) identify objects, then define each object's attributes, behaviors, and relationships

In C++11 the ________ operator swaps the members of the object being assigned with the temporary object. A) move assignment B) swap assignment C) temp assignment D) semantic assignment E) None of these

A) move assignment

How many default constructors can a class have? A) only one B) two or more C) only two D) any number E) None of these

A) only one

If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p; A) output the dereferenced value pointed to by p B) result in a compiler error C) output the address stored in p D) output the value stored in a E) None of these

A) output the dereferenced value pointed to by p. This works just like displaying the value that is pointed to by a regular pointer by dereferencing.

A function may return a pointer but the programmer must ensure that the pointer A) still points to a valid object after the function ends B) has not been assigned an address C) was received as a parameter by the function D) has not previously been returned by another function E) None of these

A) still points to a valid object after the function ends. If an object gets deleted within the function, then this would invalidate the pointer until it gets assigned again.

A structure pointer contains A) the address of a structure variable B) the dereferenced address of a structure tag C) the name and address of the structure tag D) the address of a structure tag E) None of these

A) the address of a structure variable. A pointer to a structure points to the entire structure or a structure member.

What will the following code output? int number = 22; int *var = &number; cout << var << endl; A) the address of number B) 22 C) an asterisk followed by 22 D) an asterisk followed by the address of number

A) the address of number. Var is a pointer assigned the address of number, but is not dereferenced before being displayed. This makes the program display the address.

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; A) the value stored in the variable whose address is contained in ptr B) the string "*ptr" C) the address of the variable whose address is stored in ptr D) the address of the variable stored in ptr E) None of these

A) the value stored in the variable whose address is contained in ptr. The indirection operator is used on the pointer, so we are working with the actual value of the variable it points to, not the address of the variable the pointer points to.

A(n) ________ is a special built-in pointer that is available to a class's member functions. A) this pointer B) &constructor pointer C) ~destructor *ptr D) overload operator, -> E) None of these

A) this pointer. The this pointer points to an instance of the class making the function call, which means it points to the object which is being used to call the member function.

Select all that apply. Whitespace encompasses which of the following? A) a tab B) a newline C) a space D) None of these

A, B, and C

The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order. (T/F)

False

The linear search repeatedly divides the portion of an array being searched in half. (T/F)

False. A binary search divides in half; a linear search moves from left to right.

Anonymous Enumerated Types have a defined data type. (T/F)

False. Anonymous means the enumerator does not have a specified data type, so you cannot use it to define variables.

You can skip members when initializing a structure. (T/F)

False. C++ does not offer any way to do this!

You can exclude "const" when defining a pointer to a constant. (T/F)

False. Const is necessary, otherwise it will result in a compiler error.

A destructor function can have zero to many parameters. (T/F)

False. Destructors do not have parameters and cannot accept arguements.

A function cannot modify the members of a structure. (T/F)

False. Functions can manipulate the individual members of a function freely.

The overloaded = operator copies data from one object to another so it is known as the overload copy operator. (T/F)

False. It is known as the copy assignment operator.

You can define a structure at the end of the program after all your functions. (T/F)

False. Not defining a structure before a function that uses it will result in a compiler error.

You can use the delete operator with all pointers. (T/F)

False. You should only use the delete operator with pointers that were used the new operator.

On average, an item is just as likely to be found near the beginning of an array as near the end. (T/F)

True

When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them. (T/F)

True

When you overload an operator, you can change the operator's original meaning to something entirely different. (T/F)

True

By being able to pass arrays as arguments, you can write your own functions for processing C-strings. (T/F)

True.

When you use a strongly typed enumerator in C++11 you must prefix the enumerator with the name of the enum followed by the :: operator. (T/F)

True.

You may use the <, >, <=, >=, ==, and != relational operators to compare string objects. (T/F)

True. All string objects have values, as the characters have an ASCII value.

All C-string library functions accept pointers or addresses. (T/F)

True. All three utilize pointers for their arguments.

There must be a semicolon after the closing brace of a structure. (T/F)

True. If it is missing a semicolon, it will not function properly.

In C++11 you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it. (T/F)

True. Smart pointers allocate memory automatically, and then de-allocate it in specific cases, depending on which of the three you work with.

A struct can contain members with varying data types. (T/F)

True. Structures can contain members with varied data types.

An array name is a pointer constant because the address stored in it cannot be changed at runtime. (T/F)

True. The address of the array cannot be changed while a program is running.

If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character. (T/F)

True. The function will return an uppercase character, regardless if the character was uppercase to begin with.

The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s. (T/F)

True. The indirection operator affects both s and p in this case, indicating that they are both pointers.

More than one constructor function may be defined for a class, but only one destructor may be defined for a class. (T/F)

True. There can only be one destrcutor.

Whereas object-oriented programming centers on the object, procedural programming centers on functions. (T/F)

True. These different functions are the objects

A static member function does not need to be called by a specific object of the class. (T/F)

True. They are called like other functions, but use the scope resolution operator.

If an address comes before another in memory, it is considered "less than" the second. (T/F)

True. This allows you to check for the bounds of an array using a pointer address.

The expression s->m; indicates that s is a structure pointer and m is a structure member. (T/F)

True. This is a notation stating that s "points" to m, and is much easier to understand visually.

If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end. (T/F)

True. This is the definition of a descending order.

A weak pointer does not have access to the memory that it points to. (T/F)

True. Weak pointers cannot access the memory location they point to.

An aggregate class's constructor can use a member initialization list to call the constructors for each of its member objects. (T/F)

True. You can call a constructor to make multiple objects of an aggregate class using a member initialization list.

In C++11 if you want to retrieve a strongly typed enumerator's underlying integer value, you must use a cast operator. (T/F)

True. You must cast it to retrieve an integer value instead of the enumerated value itself.

The _______ operator is used to dereference a pointer that is a member of a structure, and the __________ _________ operator is used to dereference a pointer to a structure.

indirection (*), structure pointer (->)

Both _______ and _____ member functions return the length of a string.

.length and .size

strncat

Accepts two C-strings or pointers to two C-strings, and an integer argument. The third argument, an integer, indicates the maximum number of characters to copy from the second C-string to the first C-string.

strncpy

Accepts two C-strings or pointers to two C-strings, and an integer argument. The third argument, an integer, indicates the maximum number of characters to copy from the second C-string to the first C-string. If n is less than the length of string2, the null terminator is not automatically appended to string1. If n is greater than the length of string2, string1 is padded with '\0' characters.

What will the following code output? int number = 22; int *var = &number; cout << *var << endl; A) the address of number B) 22 C) an asterisk followed by 22 D) an asterisk followed by the address of number

B) 22. Var is a pointer assigned the address of number, and is then dereferenced when displayed.

Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables? A) int temp = num1; num2 = num1; num1 = num2; B) int temp = num2; num2 = num1; num1 = temp; C) num1 = num2; num2 = num1; D) int temp = num1; num2 = temp; temp = num2; num1 = temp; E) None of these

B. This is the only choice that truly swaps the values. Look for just three lines of code and temp being mentioned twice!

This search can only work if the items within the array are sorted in order.

Binary

Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once? A) #include B) #guard C) #ifndef D) #endif E) None of these

C) #ifndef. Stands for "if not defined", and is used to determine whether a specific constant has not been defined with a #define directive.

With binary search algorithm, a maximum of ________ comparisons will be made on an array of 25,000 elements. A) 8 B) 14 C) 15 D) 16

C) 15. By setting 2^15, we get 32,768, which is the first power that equals at least or greater 25,000.

The escape sequence that represents the null terminator is A) \n B) \t C) \0 D) nullptr E) None of these

C) \0. The \0 character represents a null value in ASCII.

The advantage of a linear search is its A) complexity B) efficiency C) simplicity D) speed E) None of these

C) simplicity. The linear search goes from left to right, making it slow and inefficient. Complexity would also not be an advantage.

The ________ member variable may be accessed before any objects of the class have been created. A) private B) public C) inline D) static E) None of these

D) static

Which of the following statements is NOT valid C++ code? A) int ptr = &num1; B) int ptr = int *num1; C) float num1 = &ptr2; D) All of these are valid E) All of these are invalid

E) All of these are invalid. Choice A is not a pointer, so you cannot assign it an address. Choice B attempts to declare a variable and set it equal to another declaration, so it is invalid. Choice C is also not a pointer, so it cannot be assigned an address. This makes all of the statements invalid in C++.

When you pass a pointer as an argument to a function, you must A) declare the pointer value again in the function call B) dereference the pointer value in the function prototype C) use the #include statement D) not dereference the pointer in the function's body E) None of these

E) None of these. Pointers should not be declared again or dereferenced in the prototype, and they can be dereferenced in the function's body.

Passing a structure to a function by reference is perfectly safe. (T/F)

False. Passing by reference means the function could potentially change the values of the structure, so it is a good idea to pass it by a CONSTANT reference.

With pointer variables you can access but not modify data in other variables. (T/F)

False. Pointers also allow you to modify the data in the variable that the pointer "points" to.

A test using the isupper function will return false if the argument is an uppercase character. (T/F)

False. The isupper function would return true if the character was uppercase.

You can increment and decrement enumerator variables. (T/F)

False. They cannot be directly incremented or decremented. You must use extra code and casting to create an equivalent expression.

Before you can perform a bubble sort, the data must be stored in descending order. (T/F)

False. This would only possibly be true for search algorithms.

You cannot directly assign an enumerator to an int variable. (T/F)

False. You can assign an enumerator to an int variable, but you cannot directly assign an integer value to an enumerator.

You can multiply and divide pointers. (T/F)

False. You may add or subtract from a pointer, but never multiply or divide.

Integer values may be directly assigned to enumerators. (T/F)

False. You must cast the integer value into the enumerators data type first.

It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable. (T/F)

False. You must output each member one at a time using the dot operator.

If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded. (T/F)

False. You must overload each of them individually.

It is okay to leave a defined pointer uninitialized. (T/F)

False. You should always initialize a pointer with a valid memory address or nullptr.

When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor. (T/F)

True. C++ automatically assigns a default constructor if no constructor is defined.

C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array. (T/F)

True. C++ rarely is intelligent enough to prevent catastrophic errors on its own.

A private member function is useful for tasks that are internal to the class but it is not directly called by statements outside the class. (T/F)

True. Functions outside the class must ask the classes functions for access to private member data.

Addresses are stored in hexadecimal. (T/F)

True. This is the way addresses are normally shown in C++.

To access dynamically allocated memory, you need a _______.

You need a pointer. Dynamically allocated memory does not have a name, just an address. Therefore, it requires a pointer.

Accepts a c-string as an argument, and converts that c-string to a double and returns that value.

atof

Accepts c-string as an argument, and converts the c-string to an integer and returns that value.

atoi

Accepts a c-string as an argument, and converts that c-string to a long integer and returns that value.

atol

How many spaces would a C-string require to hold 25 characters?

26, as it requires space for the null character as well.

Given the string shown below, if the delimiter is a space, how many tokens are in the string? "Tony's email address is [email protected]" A) 4 B) 5 C) 6 D) 7 E) 9

B) 5. The delimiter is what separates different "tokens" in a string. In this case, there are 5 separate clumps of characters separated by the delimiter, which is a space.

If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr; A) It declares an empty structure variable named *pcirc. B) It declares a structure pointer called pcirc initialized with a null pointer. C) The statement is illegal in C++. D) It initializes a null pointer with the value of the Circle pointer. E) None of these

B) It declares a structure pointer called pcirc initialized with a null pointer.

Data types that are created by the programmer are known as A) variables B) abstract data types (ADTs) C) functions D) parameters E) None of these

B) abstract data types (ADTs). they are abstract because they're composed of one or more primitive data types. They also have their own range of data.

Which of the following describes only the general characteristics of an object? A) initialization B) abstraction C) detailed specification D) initiation E) None of these

B) abstraction. By definition an abstraction only describes the general characteristics of something, but no fine details.

Which of the following defines an array of C-strings that will hold 49 characters and the null terminator? A) char [49]; B) char str[50]; C) char[50] str; D) character str[50]; E) None of these

B) char str[50];. The null terminator is a character, so to hold 49 characters and the null terminator, the array needs 50 places.

When objects contain pointers, it is a good idea to create an explicit ________ function. A) destructor B) copy constructor C) static constructor D) inline constructor E) None of these

B) copy constructor

Objects are created from abstract data types that encapsulate ________ and ________ together. A) numbers, characters B) data, functions C) addresses, pointers D) integers, floating-point numbers E) None of these

B) data, functions

Where are class declarations usually stored? A) on separate disk volumes B) in their own header files C) in .cpp files, along with function definitions D) under pseudonyms E) None of these

B) in their own header files

With an enumerated data type, the enumerators are stored in memory as A) strings B) integers C) characters D) doubles

B) integers. These are not strings, as they do not use quotations. Instead, they are seen as similar to the elements in an array, which have an integer value representing them.

Which of the following will return true if the argument is a printable character other than a digit, letter, or space? A) isprint B) ispunct C) ischar D) isnotdls E) None of these

B) ispunct. This function looks for punctuation characters (which means it returns false if it only finds digits, letters, or spaces). Function isprint is the inverse of this.

To determine whether a character entered is whitespace, use the ________ function. A) iswhite B) isspace C) iswhitespace D) isblank E) None of these

B) isspace. This function checks the given argument for any whitespace characters.

The ________ is adequate for searching through small arrays. A) binary search B) linear search C) unary search D) bubble sort E) None of these

B) linear search. Due to it being far slower than a binary search, the linear search should primarily be used for smaller arrays.

What is the output of the following statement? cout << tolower(toupper('Z')) << endl; A) uppercase Z B) lowercase z C) a lowercase z followed by an uppercase Z D) a compiler error E) None of these

B) lowercase z. This statement first converts the character to uppercase, then back to lowercase.

In C++11 values that persist beyond the statement that created them and have names that make them accessible to other statements in the program are called A) rvalues B) lvalues C) temporary values D) semantics E) None of these

B) lvalues

To overload the + operator, you would write a function named A) overload + B) operator + C) function + D) operator.overload(+) E) None of these

B) operator +. All overloading is laid out in this way when programming, using the word operator followed by the operator to be overloaded.

Which type of member function may only be called from a function that is a member of the same class? A) public B) private C) global D) local E) None of these

B) private

If you do NOT declare an access specification, the default for members of a class is A) inline B) private C) public D) global E) None of these

B) private. All members of a class are automatically set to private unless otherwise specified in the class definition.

A ________ algorithm is a method of locating a specific item of information in a larger collection of data. A) sort B) search C) standard D) linear E) None of these

B) search. These algorithms "search" for a specific item within an array.

To help prevent memory leaks from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. A) null pointer B) smart pointer C) dereferenced pointer D) None of these

B) smart pointer. Smart pointers automatically de-allocate memory.

Algorithms used to arrange random data in some order are ________ algorithms. A) standard search B) sorting C) linear D) binary search E) None of these

B) sorting. Sorting algorithms arrange data in an order.

A library function that can find one C-string inside another is A) strcmp B) strstr C) strfind D) strsearch E) None of these

B) strstr. This is a function that looks for C-string inside another. Choices C and D are not real, and strcmp compares two C-strings.

If Circle is a structure tag, then the following statement can be the header line for a function that ________. Circle doSomething(Circle c2) A) determines and returns the area of a circle B) takes a Circle structure as a parameter, does something, and returns a Circle structure C) operates on a constant reference to a Circle structure D) takes two Circle parameters and does something E) None of these

B) takes a Circle structure as a parameter, does something, and returns a Circle structure. This function does not specify what it does, so it accepts a circle structure as a parameter, and then does something.

Which of the following will allow you to access structure members? A) the structure access operator B) the dot operator C) the #include directive D) the getmember function E) None of these

B) the dot operator. The dot operator used with the structure name allows you to access the individual members inside a function (such as Circle.radius).

In C++11, assuming mychar is a char variable and mystring is a string, what is the value of mychar after the following statement executes? mychar = mystring.front(); A) the ASCII value of the first character of mystring B) the first character of mystring C) nothing, the function is missing an argument D) this will cause a compiler error

B) the first character of mystring. The ".front()" member function returns the first character of the string it is being used on, so we get a character and not the ASCII value.

Which of the following is used to protect important data? A) the public access specifier B) the private access specifier C) the protect member function D) the class protection operator, @ E) None of these

B) the private access specifier. Private class members are protected from outside manipulation, as they can only be accessed by the class' own functions or friends of the class.

The arguments of the strcpy function are A) two C-strings B) two addresses C) three pointers D) one array and one pointer E) None of these

B) two addresses. Function strcpy accepts two C-string addresses as arguments, and copies the contents of the second argument into the first, including null terminator.

What is the result after the following statement executes? char var1 = tolower('A'); A) var1 stores the character value 'A' B) var1 stores the ASCII value for lowercase 'a' C) the character A is output to the monitor D) the character a is output to the monitor E) None of these

B) var1 stores the ASCII value for lowercase 'a'. Function tolower converts the argument to a lowercase character, which is stored as an ASCII value.

Dynamic memory allocation occurs A) when a new variable is created by the compiler B) when a new variable is created at runtime C) when a pointer fails to dereference the right variable D) when a pointer is assigned an incorrect address E) None of these

B) when a new variable is created at runtime. Memory is only allocated once the program begins running, not during compiling.

A good reason to overload an operator is to enable it to A) outperform its C language counterparts B) work in its usual way, but with programmer-defined data types C) operate on more operands than in its standard definition D) operate to no operands E) None of these

B) work in its usual way, but with programmer-defined data types. This allows them to work with classes. We cannot make them operate on more operands than the standard definition.

What value will BOILING have after the following statement? enum Water {FREEZING = 32, BOILING}; A) 1 B) 212 C) 33 D) 31 E) None of these

C) 33. Enumerators scale up by one more than the previous with their values.

Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr; A) The statement declares an object of the class Rectangle. B) The statement assigns the value of *BoxPtr to the object Rectangle. C) The statement defines a Rectangle pointer variable named BoxPtr. D) The statement is illegal in C++. E) None of these

C) The statement defines a Rectangle pointer variable named BoxPtr.

Which of the following is TRUE about this statement? sum += *array++; A) This statement is illegal in C++ B) This statement will cause a compiler error C) This statement assigns a dereferenced pointer's value, then increments the pointers address D) This statement increments the dereferenced pointer's value by one, then assigns that value E) None of these

C) This statement assigns a dereferenced pointer's value, then increments the pointers address. The program works from left to right here, meaning it would assign the value before incrementing anything, in this care incrementing the address of the pointer.

The following statement ________. int *ptr = new int; A) results in a compiler error B) assigns an integer less than 32767 to the variable ptr C) assigns an address to the variable ptr D) creates a new pointer named int E) None of these

C) assigns an address to the variable ptr. This statement is using the new operator, which dynamically allocates memory. The new operator is formatted as iptr = new int, where iptr will contain the address of the newly allocated memory.

The following is the pseudo-code for which type of algorithm? Set first to 0 Set last to the last subscript of the array Set found to false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array[middle] equals desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle -1 Else Set first to middle + 1 End If End While Return position A) linear sort B) linear search C) binary search D) selection sort E) None of these

C) binary search. The biggest clue is the pseudo-code setting a position for the middle. Recall that the binary search begins in the middle, and then checks that value.

A ________ search is more efficient than a ________ search. A) character, string B) integer, double C) binary, linear D) linear, binary E) None of these

C) binary, linear. The binary search eliminates half the array each time it checks a value, making it far more efficient.

When a member function is defined outside of the class declaration, the function name must be qualified with the A) class name, followed by a semicolon B) name of the first object C) class name, followed by the scope resolution operator D) private access specifier E) None of these

C) class name, followed by the scope resolution operator

A(n) ________ is a special function that is called whenever a new object is created and initialized with another object's data. A) static function B) destructor C) copy constructor D) assignment function E) None of these

C) copy constructor

Which of the following statements outputs the value of the gpa member of element [1] of the student array? A) cout << student1.gpa; B) cout << firstStudent.gpa; C) cout << student[1].gpa; D) cout << gpa[1].student; E) None of these

C) cout << student[1].gpa;

Which of the following statements deletes memory that has been dynamically allocated for an array? A) int array = delete memory; B) int delete[ ]; C) delete [] array; D) new array = delete; E) None of these

C) delete [] array;. The delete operator is used as "delete iptr" for integers and "delete [] iptr" for arrays.

In the following function header, the word int is known as a(n) ________. FeetInches FeetInches::operator++(int) A) parameterless data type B) incomplete argument C) dummy parameter D) incomplete parameter E) None of these

C) dummy parameter. The dummy parameter tells C++ that the function is designed to be used in postfix mode.

With pointer variables you can ________ manipulate data stored in other variables. A) never B) seldom C) indirectly D) directly E) None of the above

C) indirectly. These variables are not directly operating on what they are pointing to, so it is an indirect manipulation.

When the body of a member function is defined inside a class declaration, it is said to be A) static B) global C) inline D) conditional E) None of these

C) inline

A(n) ________ search uses a loop to sequentially step through an array. A) binary B) unary C) linear D) relative E) None of these

C) linear. The linear search "steps" through each element, making a loop the clear choice for the algorithm.

Assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? A) Car -> accelerate(); B) Car::accelerate(); C) myCar.accelerate(); D) myCar:accelerate(); E) None of these

C) myCar.accelerate();

When a class contains an instance of another class, it is known as A) object overloading B) operator overloading C) object composition D) dynamic composition E) None of these

C) object composition

In the following statement, what does int mean? int *ptr = nullptr; A) The variable named *ptr will store an integer value. B) The variable named *ptr will store an asterisk and an integer value C) ptr is a pointer variable and will store the address of an integer variable. D) The variable named *ptr will store the value in nullptr. E) None of these

C) ptr is a pointer variable and will store the address of an integer variable. The int is similair to declaring a variable's data type, but in the case of a pointer, means that it will point to the address of an int variable.

After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; ptr++; A) ptr will hold the address of numbers[0] B) ptr will hold the address of the second byte within the element numbers[0] C) ptr will hold the address of numbers[1] D) this code will not compile

C) ptr will hold the address of numbers[1]. Initially ptr will contain the address of numbers[0], but after incrementing, it will contain the address of the next value, numbers[1].

The ________ sort usually performs fewer exchanges than the ________ sort. A) bubble, selection B) binary, linear C) selection, bubble D) ANSI, ASCII E) None of these

C) selection, bubble. The selection sort moves items to their final positions immediately, while the bubble sort only moves each item one step up or down.

A reason to overload the ________ is to allow you to write classes that have array-like behaviors. A) parentheses ( ) operator B) curly braces { } operator C) square brackets [ ] operator D) colon :: operator E) None of these

C) square brackets [ ] operator. Arrays use square brackets, so it makes perfect sense to overload these to behave the same way with classes.

C++ allows you to redefine the way ________ work when used with class objects. A) compiler errors B) preprocessor directives C) standard operators D) undefined vriables E) None of these

C) standard operators. These are the overloaded operators.

The ________ function concatenates the contents of one C-string with another C-string. A) strcopy B) strappend C) strcat D) stradd E) None of these

C) strcat. This function concatenates (appends) the contents of a C-string into the other, with no inclusion of a whitespace character in between.

The function that accepts a pointer to a C-string as an argument and returns the length of the C-string, not including the null terminator is A) numchar B) strlength C) strlen D) countstring E) None of these

C) strlen. This function used the null terminator to determine length

To dereference a structure pointer, the appropriate operator is A) the ampersand (&) B) an asterisk (*) C) the -> operator D) the operator () E) None of these

C) the -> operator. This functions similar to the indirection operator (which can be used to dereference a pointer that is a member of a structure), but the -> operator is specifically used for structures.

When you work with a dereferenced pointer, you are actually working with A) a variable whose memory has been allocated B) a copy of the value pointed to by the pointer variable C) the actual value of the variable whose address is stored in the pointer variable D) None of these

C) the actual value of the variable whose address is stored in the pointer variable. Dereferencing means that you are working with the true value of whatever the pointer is pointing to.

If a variable uses more than one byte of memory, for pointer purposes its address is A) the address of the last byte of storage B) the average of all the addresses used to store that variable C) the address of the first byte of storage D) the address of the second byte of storage E) None of these

C) the address of the first byte of storage. This is similar to an arrays address.

The following statement ________. bookList[2].publisher[3] = 't'; A) is illegal in C++ B) will change the name of the second book in bookList to 't' C) will store the character 't' in the fourth element of the publisher member of bookList[2] D) will result in a runtime error E) None of these

C) will store the character 't' in the fourth element of the publisher member of bookList[2]. publisher[3] is the fourth element of the member.

After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PINE }; A) "MAPLE" B) 2 C) 'M' D) 1 E) 1.0

D) 1. This works similarly to arrays where the first position is given the address of 0, and the second with the value of 1, etc.

You may use a pointer to a structure as a A) function parameter B) structure member C) function return type D) All of these E) None of these

D) All of these. Functions can return a pointer, and pointers can be used as a function parameter and as a structure member.

What does the following statement do? double *num2; A) Declares a double variable names num2 B) Declares and initializes a pointer named num2 C) Initializes a pointer variable names num2 D) Declares a pointer variable named num2 E) None of these

D) Declares a pointer variable named num2. The indirection operator can be seen, indicating this is a declaration statement for a pointer variable.

The destructor function's return type is A) int B) float C) char D) Nothing; destructors have no return type E) Depends on the data type of the constructor

D) Nothing; destructors have no return type. They destroy, and do nothing else.

The expression being tested by the statement shown below will evaluate to true if var1 is ________. if (!isdigit(var1)) A) an alphabetic character B) 9 C) a symbol such as $ or & D) both an alphabetic character and a symbol such as $ or & E) None of these

D) both an alphabetic character and a symbol such as $ or &. Here we are saying "if var1 is NOT a digit, then this is true". Any character or symbol would make this statement true, as they are not digits.

Which of the following statements displays the address of the variable numb? A) cout << numb; B) cout << *numb; C) cin >> &numb; D) cout << &numb; E) None of these

D) cout << &numb;. The & operator is used before the variable name, which makes the cout statement display the address instead of the variable value.

When an array is sorted from highest to lowest, it is said to be in A) reverse order B) forward order C) ascending order D) descending order E) None of these

D) descending order. By definition, descending means from lowest to highest.

Which of the following assigns a value to the hourlyWage member of employee[2]? A) employee[2] -> hourlyWage = 50.00; B) employee2.hourlyWage = 7.50; C) hourlyWage[2].employee = 29.75; D) employee[2].hourlyWage = 75.00; E) None of these

D) employee[2].hourlyWage = 75.00;. hourlyWage is a member of the employee[2] structure, so it should be placed after the dot operator.

Which type of function is NOT a member of a class but has access to the private members of the class? A) static B) constructor C) destructor D) friend E) None of these

D) friend. All of the other choices are members of the class.

To determine whether a character entered is a letter of the alphabet, use the ________ function. A) isdigit B) ischaracter C) isletter D) isalpha E) None of these

D) isalpha. Think of this as alphanumeric.

To test whether a character is a numeric digit character, use the ________ function. A) isnumber B) notAlpha C) isnumeric D) isdigit E) None of these

D) isdigit. The isdigit function is the only true function in this list.

A binary search begins with the ________ element of an array. A) first B) last C) largest D) middle E) None of these

D) middle. Binary searches always start in the middle of the section they are searching.

When you overload an operator, you cannot change the number of ________ taken by the operator. A) arguements B) parameters C) operations D) operands E) None of these

D) operands. You can never change the number of operands taken by the operator.

In C++11 reference variables that can refer only to temporary objects that would otherwise have no name are called ________ and are declared with a ________. A) rvalues, ampersand (&) B) lvalues, ampersand (&) C) lvalues, double ampersand (&&) D) rvalues, double ampersand (&&) E) None of these

D) rvalues, double ampersand (&&)

The following statement ________. cin >> *num3; A) stores the keyboard input in the variable num3 B) stores the keyboard input into the pointer num3 C) is illegal in C++ D) stores the keyboard input into the variable pointed to by num3 E) None of these

D) stores the keyboard input into the variable pointed to by num3. Notice the indirection operator being used, which means we are using the variable the pointer points to.

In C++11, you can use a new type of enum known as a(n) ________ (also known as an enum class) to have multiple enumerators with the same name, within the same scope. A) universal enum B) auto enum C) multi-cast enum D) strongly typed enum E) None of these

D) strongly typed enum. Strongly typed enums contain extra identifiers, allowing the same name to be used for enums in seperate classes.

A linear search can only be implemented with integer values. (T/F)

False

A selection sort and a binary search can be applied to STL vectors as well as arrays. (T/F)

True


Ensembles d'études connexes

horizontal and vertical lines chapter 4 algebra

View Set

Social Studies Final Exam Chapter 19-24

View Set

Chapter 7 Microbiology - Control of Microbial Growth

View Set