Chapter 7 Review

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

Consider the following array definition: int values[5] = { 4, 7, 6, 8, 2 }; What does each of the following statements display? cout << values[4] << endl; __________ cout << (values[2] + values[3]) << endl; __________ cout << ++values[1] << endl; __________

*2* *14* *8*

If an array is partially initialized, the uninitialized elements will contain "garbage."

*False*

You can use the [] operator to insert a value into a vector that has no elements.

*False*

You can write programs that use invalid subscripts for an array.

*False*

The _________ indicates the number of elements, or values, an array can hold

The *size declarator* indicates the number of elements, or values, an array can hold.

To define a two-dimensional array, _________ size declarators are required.

To define a two-dimensional array, *two* size declarators are required.

To define a vector in your program, you must #include the ____________ header file

To define a vector in your program, you must #include the *vector* header file.

To determine the number of elements in a vector, use the _____________ member function

To determine the number of elements in a vector, use the *size* member function.

To pass an array to a function, pass the _________ of the array.

To pass an array to a function, pass the *name* of the array.

To store a value in a vector that does not have a starting size, or that is already full, use the ________________ member function.

To store a value in a vector that does not have a starting size, or that is already full, use the *push_back* member function.

Use the ________________ member function to remove the last element from a vector

Use the *pop_back* member function to remove the last element from a vector.

How do you define an array without providing a size declarator?

We define an array without providing a size declarator or by providing an initialization list.

When a two-dimensional array is passed to a function the _________ size must be specified.

When a two-dimensional array is passed to a function the column size must be specified.

When initializing a two-dimensional array, it helps to enclose each row's initialization list in _________.

When initializing a two-dimensional array, it helps to enclose each row's initialization list in *braces*.

You cannot use the _________ operator to copy data from one array to another in a single statement.

You cannot used the *equal* operator to copy data from one array to another in a single statement.

Assuming that array1 and array2 are both arrays, why is it not possible to assign the contents of array2 to array1 with the following statement? array1 = array2;

Array name without brackets and a subscript represents the array's beginning memory address. This will assign address of array2 to array1 and is no permitted.

Is an array passed to a function by value or by reference?

Array passed to a function by reference.

C++ has no array _________ checking, which means you can inadvertently store data past the end of an array

C++ has no array *bounds* checking, which means you can inadvertently store data past the end of an array

If an array is partially initialized, the uninitialized elements will be set to _________.

If an array is partially initialized, the uninitialized elements will be set to *zero*.

If the size declarator of an array definition is omitted, C++ counts the number of items in the _________ to determine how large the array should be

If the size declarator of an array definition is omitted, C++ counts the number of items in the *initialization list* to determine how large the array should be.

It's best to think of a two-dimensional array as having _________ and _________.

It's best to think of a two-dimensional array as having *rows* and *columns*.

When you pass an array name as an argument to a function, what is actually being passed?

Passing array name to function will pass memory address of array.

char greeting[] = {'H', 'e', 'l', 'l', 'o'}; cout << greeting;

char greeting[] = {'H', 'e', 'l', 'l', 'o'}; *// a null terminator must be specified in the initialization list* cout << greeting;

float ratings[];

float ratings[]; *//need size declarator or initialization list*

int collection[-20];

int collection[-20]; *//size declarator cannot be negative*

int table[10]; for (int x = 0; x < 20; x++) { cout << "Enter the next value: "; cin >> table[x]; }

int table[10]; for (int x = 0; x < 20; x++) *//invalid access of array* { cout << "Enter the next value: "; cin >> table[x]; }

void showValues(int nums) { for (int count = 0; count < 8; count++) cout << nums[count]; }

void showValues(int nums) { for (int count = 0; count < 8; count++) cout << nums[count]; } *//the function should have a parameter to hold array elements and size parameter must also be there*

Look at the following array definition. int numbers[5] = { 1, 2, 3 }; What value is stored in numbers[2]? What value is stored in numbers[4]?

*3* *0* (value is not initialized)

A vector is an associative container.

*False*

An array's size declarator can be either a literal, a named constant, or a variable.

*False*

Arrays cannot be initialized when they are defined. A loop or other means must be used.

*False*

If you leave an element uninitialized, you do not have to leave all the ones that follow it uninitialized.

*False*

If you leave out the size declarator of an array definition, you do not have to include an initialization list

*False*

The contents of an array element cannot be displayed with cout.

*False*

The first element in an array is accessed by the subscript 1.

*False*

The first size declarator (in the declaration of a two-dimensional array) represents the number of columns. The second size definition represents the number of rows.

*False*

Two-dimensional arrays may be passed to functions, but the row size must be specified in the definition of the parameter variable.

*False*

When an array name is used without brackets and a subscript, it is seen as the value of the first element in the array.

*False*

When writing a function that accepts a two-dimensional array as an argument, which size declarator must you provide in the parameter for the array?

*Passing Two-Dimensional Arrays to Functions* If a function accepts a two-dimensional array as an argument, then second size declarator (column size declarator) must be provided in the parameter for the array. *Example:* The following function has two dimensional array as an argument with column size declarator is provided in the parameter for the array. int functionName(int array1 [][5], int rows1);

A two-dimensional array is like several identical arrays put together.

*True*

C++ allows you to create arrays with three or more dimensions.

*True*

C++ allows you to partially initialize an array.

*True*

If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value.

*True*

It's best to think of two-dimensional arrays as having rows and columns.

*True*

Subscript numbers may be stored in variables.

*True*

The individual elements of an array are accessed and indexed by unique numbers.

*True*

The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array.

*True*

The uninitialized elements of a string array will automatically be set to the value "0".

*True*

The values in an initialization list are stored in the array in the order they appear in the list.

*True*

To calculate the amount of memory used by an array, multiply the number of elements by the number of bytes each element uses

*True*

To pass an array to a function, pass the name of the array.

*True*

To use a vector, you must include the vector header file.

*True*

When an array is passed to a function, the function has access to the original array.

*True*

When defining a parameter variable to hold a single-dimensional array argument, you do not have to include the size declarator.

*True*

You cannot use the assignment operator to copy one array's contents to another in a single statement.

*True*

vectors can report the number of elements they contain.

*True*

A(n) _________ array is like several arrays of the same type put together.

A *two-dimensional* array is like several arrays of the same type put together.

Any time the name of an array is used without brackets and a subscript, it is seen as _________.

Any time the name of an array is used without brackets and a subscript, it is seen as *the array's beginning memory address*.

Look at the following array definition. double sales[8][10]; How many rows does the array have? How many columns does the array have? How many elements does the array have? Write a statement that stores a number in the last column of the last row in the array

Array has *8 rows*. Array has *10 columns*. Array has *80 elements*. sales[7][9] = 53.61

By using the same _________ for multiple arrays, you can build relationships between the data stored in the arrays

By using the same *subscript* for multiple arrays, you can build relationships between the data stored in the arrays.

Each element of an array is accessed and indexed by a number known as a(n) _________.

Each element of an array is accessed and indexed by a number known as a *subscript*.

How do you establish a parallel relationship between two or more arrays?

Establishing parallel relationship between two or more arrays can be done by using the same subscript value for each array.

Why should a function that accepts an array as an argument, and processes that array, also accept an argument specifying the array's size?

In order to process array in function passing array alone cannot determine the number of elements in array, therefore we need array size argument also.

Starting values for an array may be specified with a(n) _________ list.

Starting values for an array may be specified with an *initialization* list.

Subscript numbering in C++ always starts at _________.

Subscript numbering in C++ always starts at *zero*.

The ____________________ is a collection of programmer-defined data types and algorithms that you may use in your programs.

The *Standard Template Library* is a collection of programmer-defined data types and algorithm that you may use in your programs.

Look at the following array definition. int values[10]; How many elements does the array have? What is the subscript of the first element in the array? What is the subscript of the last element in the array? Assuming that an int uses four bytes of memory, how much memory does the array use?

The array has *10* elements. The subscript of the first element in the array is *zero*. The subscript of the last element in the array is *9*. Then the array uses *40 bytes* of memory.

What advantages does a vector offer over an array?

The main advantages of a vector over an array are: 1. You do not have to declare the number of elements that a vector will have. 2. If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value. 3. A vector can report the number of elements it contains.

The number inside the brackets of an array definition is the _________, but the number inside an array's brackets in an assignment statement, or any other statement that works with the contents of the array, is the _________.

The number inside the brackets of an array definition is the *size declarator*, but the number inside an array's brackets in an assignment statement, or any other statement that works with the contents of the array, is the *subscript*.

What is the difference between a size declarator and a subscript?

The number inside the brackets of an array definition is the size declarator. The size declarator is used in the array declaration statement. It specifies the number of elements in the array. The number inside the brackets of an assignment statement or any statement that works with the contents of an array is a subscript. A subscript is used to access an individual element in an array.

The size declarator must be a(n) _________ with a value greater than _________.

The size declarator must be an *integer* with a value greater than *zero*.

Assuming that numbers is an array of doubles, will the following statement display the contents of the array? cout << numbers << endl;

The statement will not display the contents of array instead it will display the memory address.

The two types of containers defined by the STL are ___________ and ______________.

The two types of containers defined by the STL are *sequence containers* and *associative containers*.

The vector data type is a(n) ______________ container

The vector data type is a sequence container.

To completely clear the contents of a vector, use the ___________ member function

To completely clear the contents of a vector, use the *clear* member function.

int array1[4], array2[4] = {3, 6, 9, 12}; array1 = array2;

int array1[4], array2[4] = {3, 6, 9, 12}; array1 = array2; *//the assignment operator can't be used to assign the contents of one array to another in a single statement*

int hours[3] = 8, 12, 16;

int hours[3] = 8, 12, 16; *//array initialization must be enclosed with braces*

int numbers[8] = {1, 2, , 4, , 5};

int numbers[8] = {1, 2, , 4, , 5}; *//cannot leave initialization values blank*

int size; double values[size];

int size; *// Must be provided with initial value* double values[size];


Set pelajaran terkait

COSC 3355 Operating System Concepts Chapters 1-4

View Set

PrepU Accountability Nursing Concept

View Set

English 2 Honors ethos, pathos and logos definitions

View Set

MKTG 3600 Chapter 7 Activity UVU

View Set

Midterm 2 Material: Topic 4- Gene Interaction, Inheritance and phenotype and Topic 5-

View Set

Football Stars Messi and Ronaldo Audio Bio from http://www.famouspeoplelessons.com/ Glossary in English and Catalan by mnaves3

View Set