COSC 1337 Midterm Review

¡Supera tus tareas y exámenes ahora con Quizwiz!

What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; }

60

What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl;} TestClass() { cout << "Hello!" << endl; } }; int main() { TestClass test(77); return 0; }

77

A destructor function can have zero to many parameters.

False

A linear search can only be implemented with integer values.

False

Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.

False

Class objects can be defined prior to the class declaration.

False

Constructor functions are often used to allocate memory that will be needed by the object.

False

In-place member initialization no longer is available in C++11.

False

The ampersand (&) is used to dereference a pointer variable in C++.

False

The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.

False

The linear search repeatedly divides the portion of an array being searched in half.

False

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>();

It specifies that only String objects may be stored in the ArrayList object.

The string class's front and back member functions were introduced in C++11.

True

The escape sequence that represents the null terminator is

\0

What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;

a = 5

A pointer variable may be initialized with

a valid address in the computer's memory

The ________, also known as the address operator, returns the memory address of a variable.

ampersand ( & )

The function that converts a C-string to an integer and returns the integer value is

atoi

Which of the following converts the string "10" to the integer value 10?

atoi("10");

In OOP terminology, an object's member variables are often called its ________ and its member functions can be referred to as its behaviors or its ________.

attributes, methods

When a constructor has a member initialization list, the initializations take place

before any statements in the body of the constructor execute

A ________ is a member function that is automatically called when a class object is ________.

constructor, created

Use the delete operator only on pointers that were

created with the new operator

A class is a(n) ________ that is defined by the programmer.

data type

When an array is sorted from highest to lowest, it is said to be in

descending order

Each array in Java has a public field named ________ that contains the number of elements in the array.

length

The following is the pseudocode for which type of algorithm? Set found to false Set position to -1 Set index to 0 While found is false and index < number of elements If list[index] is equal to search value found = true position = index End If Add 1 to index End While Return position

linear search

To return an array of long values from a method, use this as the return type for the method.

long[]

A binary search begins with the ________ element of an array.

middle

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?

myCar.accelerate();

In C++ a C-string is a sequence of characters stored in consecutive memory, terminated by a

null sequence

If numbers is a two-dimensional array, which of the following would give the length of row r?

numbers[r].length

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [][])

A ________ algorithm is a method of locating a specific item of information in a larger collection of data.

search

The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 To size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with array[start] End For

selection sort

The ________ function concatenates the contents of one C-string with another C-string.

strcat

A library function that can find one C-string inside another is

strstr

The ________ and ________ operators can be used to increment or decrement a pointer variable.

++, --

Which of the statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];

-Declares array1 to be a reference to an array of long values -Creates an instance of an array of 10 long values -Will allow valid subscripts in the range of 0 - 9 ANSWER: All of the above

The function that accepts a C-string as an argument and converts the string to a long integer is

-atol -strlong -strtolong -stringlong ANSWER: None of these

Which of the following will return true if the argument is a printable character other than a digit, letter, or space?

-isprint -ispunct -ischar -isnotdls ANSWER: None of these

The null terminator stands for ASCII code

0

The last subscript in an array is always __________.

1 less than the number of elements

What is the value stored in num after the following statement executes? num = atoi("1000");

1000

What would be the results of the following code? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; }

This would cause the program to crash.

A pointer can be used as a function argument, giving the function access to the original argument.

True

A selection sort and a binary search can be applied to STL vectors as well as arrays.

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

In C++11, the nullptr keyword was introduced to represent the address 0.

True

Java does not limit the number of dimensions that an array may have.

True

More than one constructor function may be defined for a class.

True

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 desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position

binary search

Which of the following statements appropriately defines a C-string that stores names of up to 25 characters?

char name[26];

In memory, an array of String objects:

consists of elements, each of which is a reference to a String object

Data that is to be sorted in ascending order is ordered

from lowest value to highest value

The process of object-oriented analysis can be viewed as the following steps:

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

Select all that apply. Which of the following would be appropriate in a program that allows the user to enter either an uppercase or lowercase character in response to a prompt?

ignorecase

Where are class declarations usually stored?

in their own header files

In C++11 you can use ________ to initialize a member variable in its declaration statement.

in-place initialization

The following code shows an example of ________ class Point { private: double y = 5.70; double z = 3.0; public: public member functions go here... };

in-place initialization

In Java, you do not use the new operator when you use a(n):

initialization list

A search algorithm:

is a method of locating a specific item of information in a larger collection of data.

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

Array elements must ________ before a binary search can be performed.

sorted

Algorithms used to arrange random data in some order are ________ algorithms.

sorting

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

What will the following code output? int number = 22; int *var = &number; cout << var << endl;

the address of number

When the less than operator (<) is used between two pointer values, the expression is testing whether

the address of the first variable comes before the address of the second variable in the computer's memory

If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with

the integer 0 or the value NULL

The ________ is adequate for searching through small arrays.

the linear search

What will the following statement output? cout << &num1;

the memory address of the variable named num1

When an individual element of an array is passed to a method:

the method does not have direct access to the original array

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

the value stored in the variable whose address is contained in ptr


Conjuntos de estudio relacionados

Intermediate Macroeconomic Theory Unit 1

View Set

Surah Baqarah Ayahs 1-100 Arabic/English Translation (Saheeh International)

View Set

Statistical Studies: Designing a Study (Quiz) ~amdm

View Set

Types of Life Insurance quiz missed

View Set

India : States, Union Territories and their Capitals

View Set