Chapter 7 - Arrays

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

7.2 How would you pronounce this? hours[0] = 20;

"hours sub zero is assigned twenty" or "hours sub zero gets twenty" p. 380

7.2 You can use any array integer expression as...

You can use any integer expression as an array subscript. for (int count = 1; count <= NUM_EMPLOYEES; count++) { cout << "Enter the hours worked by the employee " << count <<": "; cin >> hours[count - 1]; } In this expression the cin statement uses the expression, count - 1 , as a subscript p. 384

7.4 If you leave an element uninitialized...

... you must leave all the elements that follow it uninitialized as well. C++ does not provide a way to skip elements in the initialization list. int array[6] = {2, 4, 8, , 12]; // Not legal! p.393

7.4 Talk about array definitions.

Arrays may be initialized when they are defined. p. 389

7.2 What do question marks mean with regard to arrays?

Because values have not been assigned to other elements of the array, question marks will be used to indicate that the contents of those elements are unknown. If an array is defined globally, all of its elements are initialized to zero, by default. Local arrays, however, have no default initialization value. P. 380

7.4 True or False: C++ does not allow you to spread the initialization list across multiple lines.

False. C++ does all you to spread the initialization list across multiple lines. p. 391

7.3 What are off-by-one errors?

In working with arrays, a common type of mistake is the off-by-one error. This is an easy mistake to make because array subscripts start at zero, rather than one. p. 388

7.4 What is implicit array sizing?

It's possible to define an array without specifying an initialization list. C++ automatically makes the array large enough to hold all initialization values. double ratings [ ] = {1.0, 1.5, 2.0, 2.5, 3.0}; p. 393

7.1 Typical array sizes

char - 1 byte short - 2 bytes int - 4 bytes float - 4 bytes double 8 bytes p. 379

7.1 Valid array definitions

float temperatures[100); // An array of 100 floats string names[10]; // Array of 10 string objects long units[50]; // Array of 50 long integers double sizes[1200]; // Array of 1200 doubles p. 378

7.4 You must provide an _______ if you leave out an array's size declarator.

initialization list. p. 394

7.5 How do you decrements a value stored in an array?

use the following statement. amount[count]--; p. 394

7.5 When using the increment and decrement operators, be careful not to...

... confuse the subscript with the array element. amount[count --]; // decrements the variable count but does nothing to the value in amount. p. 394

7.5 Any time the name of an array is used without brackets and a subscript...

... it is seen as the array's beginning memory address. p. 396

7.5 Individual array elements are processed...

... like any other variable. p. 394

7.2 Inputting data into an array must normally be done ...

... one element at a time. cin >> hours; // will not input data to the hours array You must use multiple cin statements to read data into each array element or use a loop to step through the array, reading data into its elements. p. 384

7.2 Outputting an arrays elements must be done...

... one element at a time. cout << hours; // will not work p. 384

7.3 C++ does not prevent you from...

... overwriting an arrays bounds. C++ does not provide many of the common safeguards to prevent unsafe memory access found in other languages. p. 386

7.2 How do you read data from a file to an array?

Reading the contents of a file into an array is straight forward. - Open the file and use a loop to read each item from the file, storing each item in an array element. - The loop should iterate until either the array is filled or the end of the file has been reached. p. 384

7.2 How do you access array elements?

The individual elements of an array are assigned unique subscripts. These subscripts are used to access the elements. Even though an entire array has only one name, the elements may be accessed and used as individual variables. p. 379

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

The number inside the brackets of an array definition is the size declarator. The number inside the brackets of an assignment statement, or any statement that works with the contents is a subscript. p. 380

7.5 True or False: Array elements may also be used in relational expressions.

True p. 396

7.2 How do you write the contents of an array into a file?

Use a loop to step through each element of the array, writing its contents to a file. p. 385

7.4 If an array is partially initialized, the uninitialized elements will be...

... set to zero. The uninitialized elements of a string array will contain an empty string. This is true even if the string is defined locally. p. 393

7.5 The only way to assign one array to another is...

... to assign the individual elements in the arrays. Usually, this is done best with a loop for(int count = 0; count < SIZE; count++0 newValues[count] = oldValues[count]; p. 396

7.2 What is a subscript?

A subscript is used as an index to pinpoint a specific element within an array. The first element is assigned subscript 0, the second element is assigned 1 and so on... short hours[6]; // Has subscripts 0-5 p. 379

7.1 What is an array?

An array allows you to store and work with multiple value of the same data type. An array works like a variable that can store a group of values, all of the same type. The values are stored together in consecutive memory locations p. 377

7.1 What is an arrays size declarator?

An arrays size declarator indicates the number of elements, or values, that an array can hold. The size declarator must be a constant integer expression with a value greater than zero. It can be either a literal or a named constant. const int NUM_DAYS = 6; <-- Size declarator int days[NUM_DAYS];

7.4 If a local array is completely uninitialized, its elements will contain "garbage", like all other local variables. p. 393

left blank intentionally


Conjuntos de estudio relacionados

Chapter 15: Infection and Human Immunodeficiency Virus Infection

View Set

Ch 4 Introduction to Probabilities

View Set

Optics of the Eye Quiz #1 Material (Lectures 1-9)

View Set