Computer Programming Chapter 7 function

Ace your homework & exams now with Quizwiz!

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

TWO

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

Two-dimensional

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

Zero

Subscript numbering in C++ always starts at _________.

Zero

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

address, or name

What advantages does a vector offer over an array?

1. You do not have to declare the number of elements that the vector will have. 2. If you had value to a full vector, it will automatically increase it size, rather than go over like an array. 3. A vector can report the number of elements it contains

Look at the following array definition. int values[10]; How many elements does the array have? What is the subscript of the 1st 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?

10 elements Subscript of the 1st element is zero Subscript of the last element is 9 The array used 40 bytes of memory

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

<Vector>

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

=

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

Array's beginning memory address

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;

Because an array name without brackets and a subscript represents the array's beginning memory address. The statement shown attempts to assign the address of array2 to array1, which is not permitted.

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

Because, with the array alone the function has no way of determining the number of elements it has.

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

Bounds

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

By providing an initialization list. The array is sized to hold the number of values in the list.

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

By using the same subscript value for each array.

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

Clear

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

Column

float ratings[];

For the array to be implicitly sized there must be an initialization list.

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

Integer with a value greater than zero

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

Literal or named constant

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

Passing array name to function will pass address of array of integers

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

braces []

In a program you need to store the identification numbers of 10 employees (as ints) and their weekly gross pay (as doubles). Display their weekly pay.

const int SIZE = 10; int id[SIZE]; // To hold ID numbers double weeklyPay[SIZE]; // To hold weekly pay for (int i = 0; i < SIZE; i++) { cout << "The pay for employee " << id[i] << " is $" << fixed << showpoint << setprecision(2) << weeklyPay[i] << endl; }

The arrays numberArray1 and numberArray2 have 100 elements. Write code that copies the values in numberArray1 to numberArray2.

const int size = 100; for(int i = 0; i < size; i++) numberArray1[i] = numberArray2[i];

names is an integer array with 20 elements. Write a for loop that prints each element of the array.

const int size = 20; for(int i = 0; i < size; i++) cout << names[i] << endl;

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

initialization

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.

initialization list

Define two arrays that may be used in parallel to store the 10 ID numbers and gross pay amounts.

int ID[10]; double Emp[10];

Define a two-dimensional array of integers named grades. It should have 30 rows and 10 columns.

int grades[30][10];

int numberArray[9][11]; a statement that assigns 145 to the first column of the first row of this array. a statement that assigns 18 to the last column of the last row of this array

int numberArray[0][0] = 145; int numberArray[8][10] = 18;

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]?

int numbers[5] = { 1, 2, 3 }; What value is stored in numbers[2]? 3 What value is stored in numbers[4]? 0, its value is not initialized

Write code that sums all the elements in the array and stores the sum in the variable total

int values[10][20]; int row, col; // loop counter float total = 0.0 // Accumlator for(row = 0, col = 0; row < 10, col < 20; row++, col++) total += values[row][col]

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; __________

int values[5] = { 4, 7, 6, 8, 2 }; cout << values[4] << endl; 2 cout << (values[2] + values[3]) << endl; 14 cout << ++values[1] << endl; 8

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

pop_back

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

push_back

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

reference

Its best to think of a two-dimensional array as having _________ and _________.

rows and columns

The vector data type is a(n) ______________ container

sequence

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

size

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

size declarator

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 _________.

size declarator, subscript

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

subscript

Write a definition statement for a vector named frogs . frogs should be an empty vector of int s.

vector <int> frogs;

gators is an empty vector of int s. Statement that stores the value 27 in gators .

vector <int> gators; gators.push_back(27);

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

...

Its best to think of two-dimensional arrays as having rows and columns.

...

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

...

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

...

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

...

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

...

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

...

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

Sequence container and associative container

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

Standard Template Library (or STL)

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

Subscript

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

The assignment operator cannot be used to assign the contents of one array to another, in a single statement

void showValues(int nums[4][]) { for (rows = 0; rows < 4; rows++) for (cols = 0; cols < 5; cols++) cout << nums[rows][cols]; }

The parameter must specify the number of columns, not the number of rows.

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?

The second size declarator, which is for the number of columns.

int collection[-20];

The size declarator cannot be negative.

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

The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element in an array.

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

double sales[8][10]; How many rows does the array have? 8 Rows How many columns does the array have? 10 columns How many elements does the array have? 80 elements Sales[7][9] = 53.1; stores double in the last column of the last row in the array


Related study sets

Chapter 1: Sociology of the family

View Set

Introduction of the Chinese Language Study Guide

View Set

[CHEMISTRY]: Chapter 2: Gases-- Kinetic Molecular Theory (KMT)

View Set

Exam 4 Sociology (Chap. 14 - 18) --> Wrong 1 item

View Set

15:Infectious and Chronic Diseases [Defenses Against Disease]

View Set

chapter 22 psychotherapeutic drugs: pharm exam 2

View Set