The midterm
?
?
You may use a pointer to a structure as a
All of these
Which of the following statements is NOT valid C++ code?
All of these are invalid
The function that accepts a -string as an argument and converts the string to a long integer is
Atol
The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.
False
With pointer variables you can access but not modify data in other variables.
False
You cannot directly assign an enumerator to an int variable.
False
To test whether a character is a numeric digit character, use the function.
Isdigit
To determine whether a character entered is whitespace, use the function.
Isspace
If Circle is a structure, what does the following statement do? Circle *pcirc nullptr;
It declares a structure pointer called pcirc initialized with a null pointer.
A(n) search uses a loop to sequentially step through an array.
Linear
What is the output of the following statement? cout << tolower (toupper ('Z') ) << endl:
Lowercase z
A binary search begins with the element of an array.
Middle
A. algorithm is a method of locating a specific item of information in a larger collection of data.
Search
The sort usually performs fewer exchanges than the sort.
Selection, bubble
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
Smart pointer
Algorithms used to arrange random data in some order are algorithms.
Sorting
The function concatenates the contents of one C-string with another C-string.
Strcat
What will the following code output? int number - 22; int *var = &number: cout << var << endl;
The address of number
Which of the following will allow you to access structure members?
The dot operator
The is adequate for searching through small arrays.
The linear search
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.
True
The expression s->m; indicates that s is a structure pointer and m is a structure member.
True
The number of comparisons made by a binary search is expressed in powers of two.
True
You may use the <, > <== ==, and ! = relational operators to opmpare string objects.
True
An array name is a pointer constant because the address stored in it cannot be changed at runtime.
Trye
The arguments of the strepy function are
Two addresses
The escape sequence that represents the null terminator is A
\0
Which of the following assigns a value to the hourlyWage member of employee [2]?
employee [2] .hourlyWage = 75 .00 :
Whereas object-oriented programming centers on the object, procedural programming centers on functions? True A destructor function can have zero to many parameters? False More than one constructor function may be defined for a class, but only one destructor may be defined for a class? True 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? True When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor? 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? True Objects are created from abstract data types that encapsulate-and-together? Data,functions Where are class declarations usually stored? In their own header files A class is a(n)—that is defined by the programmer? Data type Which of the following is used to protect important data? The private access specifier 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? #ifindef When the body of a member function is defined inside a class declaration, it is said to be? #inline The destructor function's return type is? Nothing; destructors have no return type If you do NOT declare an access specification, the default for members of a class is? Private Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr;? • The statement defines a Rectangle pointer variable named BoxPtr. Which type of member function may only be called from a function that is a member of the same class? Private How many default constructors can a class have? Only one The process of object-oriented analysis can be viewed as the following steps? ) identify objects, then define each object's attributes, behaviors, and relationships When a member function is defined outside of the class declaration, the function name must be qualified with the? Class name, followed by the scope 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? My car.accelerate(); When you overload an operator, you can change the operator's original meaning to something entirely different. True The overloaded = operator copies data from one object to another so it is known as the overload copy operator. False If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded. False A static member function does not need to be called by a specific object of the class. True An aggregate class's constructor can use a member initialization list to call the constructors for each of its member objects. True The— member variable may be accessed before any objects of the class have been created. Static C++ allows you to redefine the way—work when used with class objects. Standard operators When objects contain pointers, it is a good idea to create an explicit—functions? Copy constructor A good reason to overload an operator is to enable it to? • work in its usual way, but with programmer-defined data types When a class contains an instance of another class, it is known as, object composition A reason to overload the—is to allow you to write classes that have array-like behaviors? Square brackets () operator Which type of function is NOT a member of a class but has access to the private members of the class? Friend An— is a special function that is called whenever a new object is created and initialized with another object's data? Copy constructor To overload the + operator, you would write a function named? Operator+ An—is a special built-in pointer that is available to a class's member functions? This pointer When you overload an operator, you cannot change the number of—taken by the operator? Operands In the following function header, the word int is known as a(n) FeetInches FeetInches::operator++ (int) — dummy parameter In C++11 values that persist beyond the statement that created them and have names that make them accessible to other statements in the are called?? Lvalues 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 —? Rvalues-double ampersand (&&) In c++11 the — operator swaps the members of the object being assigned with the temporary object? Move assignment
good luck
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?
int temp = num2; num2 = numl; numl = temo:
Which of the following will return true if the argument is a printable character other than a digit, letter, or space?
ispunct
In the following statement, what does int mean? int *ptr nullptr;
ptr is a pointer variable and will store the address of an integer variable.
After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1. 2, 3, 4} ; int *ptr numbers; ptrtt;
ptr will hold the address of numbers [1]
What is the result after the following statement executes? char varl = tolower ('A' ); A
var1 stores the ASCII value for lowercase "a'
Dynamic memory allocation occurs
when a new variable is created at runtime
The following statement bookList[2].publisher[3] It'
will store the character "t' in the fourth element of the publisher member of bookList (44
After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PINE J;
1
What is the value stored in num after the following statement executes? num = atoi ("1000");
1000
With binary search algorithm, a maximum of comparisons will be made on an array of 25,000 elements
15
Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, Correct!
20000
Given the string shown below, if the delimiter is a space, how many tokens are in the string? "Tony's email address is tony [email protected]"
5
The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in 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 the desired value Set found to true Set position to middle Else If array[middle) is greater than the destred value Set last to middle Else Set first to middle End If End While Return position
Binary search
A search is more efficient than a search.
Binary, linear
When a structure is passed to a function, its members are NOT copied.
By reference
What does the following statement do? double *num2;
Declares a pointer variable named num2
A function cannot modify the members of a structure.
False
A linear search can only be implemented with integer values.
False
A test using the i supper function will return false if the argument is an uppercase character.
False
Before you can perform a bubble sort, the data must be stored in descending order.
False
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.
False
To dereference a structure pointer, the appropriate operator is
The —> operator
Which of the following is TRUE about this statement? sum += *array++;
This statement assigns the dereferenced pointer's value, then increments the pointer's address.
A selection sort and a binary search can be applied to STL vectors as well as arrays.
True
A struct can contain members with varying data types
True
By being able to pass arrays as arguments, you can write your own functions for processing C-strings.
True
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
True
If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character.
True
If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.
True
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.
True
On average, an item is just as likely to be found near the beginning of an array as near the end.
True
Data types that are created by the programmer are known as
abstract data types (ADTs)
Which of the following describes only the general characteristics of an object?
abstraction
The following statement int *ptr = new int;
assigns an address to the variable named ptr
The expression being tested by the statement shown below will evaluate to true if var1 is if (!isdigit (varl))
both an alphabetic character and a symbol such as $ or &
Which of the following defines an array of C-strings that will hold 49 characters and the null terminator?
char str[50];
Which of the following statements displays the address of the variable numb?
cout << &numb;
When an array is sorted from highest to lowest, it is said to be in
descending order
Which of the following statements deletes memory that has been dynamically allocated for an array?
delete [] array;
When you pass a pointer as an argument to a function, you must
none of these
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;
output the dereferenced value pointed to by p
The advantage of a linear search is its
simplicity
The following statement cin >> *num3;
stores the keyboard input into the variable pointed to by num3
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
strlen
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.
strongly typed enum
A library function that can find one C-string inside another is
strstr
If Circle is a structure tag, then the following statement can be the header line for a function that Circle doSomething (Circle c2)
takes a Circle structure as a parameter, does something, and returns a Circle structure
When you work with a dereferenced pointer, you are actually working with
the actual value of the variable whose address is stored in the pointer variable
A structure pointer contains
the address of a structure variable
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 () ;
the first character of mystring
Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; Correct!
the value stored in the variable whose address is contained in pt r