61 terms

CS Chapter 7 Review

STUDY
PLAY

Terms in this set (...)

arrays and vectors
List and tables of values can be stored in ____ or _____.
array name, type
an array's elements are related by the fact that they have the same _____ and _____.
subscript or index
the number used to refer to a particular element of an array is called its?
constant variable
A(n) ___ should be used to declare the side of an array, because it eliminates magic numbers.
sorting
the process of placing the elements of an array in order is called ___ the array.
searching
the process of determine if an array contains a particular key value is called ____ the array.
2-dimensional
an array that uses two subscripts is referred to as a(n) ___ array.
F (an array can store only values of the same type)
A given array can be stored many different types of values. T or F?
F ( an array subscript should be an integer or an integer expression)
An array subscript should normally be of data type float. T or F?
F (the remaining elements are initialized to zero)
If there are fewer initializers in an initializer list then the number of elements in the array, the remaining elements are initialized to the last value in the initializer list. T or F?
True
It's an error if an initializer list has more initializer than there are elements in the array.
const size_t arraySize = 10
Write one or more statements that performs the following tasks for an array called functions: Define a constant variable arraySize to represent the size of an array and initialize it to 10.
array < double, arraySize > fractions = {0.0 };
Write one or more statements that performs the following tasks for an array called functions: Declare an array with arraySize elements of type double, and initialize the elements to zero.
fractions [3]
Write one or more statements that performs the following tasks for an array called functions: Name the forth element of the array.
fractions [4]
Write one or more statements that performs the following tasks for an array called functions: refer to array element 4.
fractions [9] = 1.667 ;
Write one or more statements that performs the following tasks for an array called functions: assign the value 1.667 to array element 9.
fractions [6] = 3.333;
Write one or more statements that performs the following tasks for an array called functions: Assign the value 3.333 to the seventh element of the array.
cout << fixed << setprecision(2);
cout << fractions[6] << ' ' << fractions[9] <<endl;

outputL 3.33 1.67
Write one or more statements that performs the following tasks for an array called functions: Display array elements 6 and 9 with two digits of precision to the right of the decimal point, and show the output that is actually displayed on the screen.
for(size_t i = 1; i < functions.size(); ++i)
cout <<"fractions[" << i << "] << fractions[i] <<endl;
Write one or more statements that performs the following tasks for an array called functions: Display all the array elements using a counter- controlled for statement. Define the integer variable i as a control variable for the loop.
for ( double elements : fractions)
cout << elements << ' ';
Write one or more statements that performs the following tasks for an array called functions: Display all the array elements separated by spaces using a range based for statement
array < array < int, arraySize >, arraySize > table;
Anwser the following questions regarding an array called table: Declare the array to store int values to have 3 rows and 3 columns. Assume that the constant variable arraySize has been defined to be 3.
nine
Anwser the following questions regarding an array called table: How many elements does the array contain if it has 3 rows and columns?
Error: semicolon at end of #include
Correction: eliminate semicolon
Find the error in each of the following program segments and correct the error:
#include <iostream>;
Error: Assigning a value to a constant variable using an assignment statement
Correction: initialize the constant variable in a const size_t arraySize declaration
Find the error in each of the following program segments and correct the error:
arraySize = 10; // arraySize declared const
Error: referencing an array element outside the bounds array (b[10])
Correction: change the loop- continuation condition to use < rather then <=
Find the error in each of the following program segments and correct the error:
Assume that array< int, 10> b = {};
for (size_t i = 0; i <= b.size(); ++i )
b[ i ] = 1;
Error: array subscript done incorrectly
Correction: Change the statement to a [ 1 ][ 1 ] = 5;
Find the error in each of the following program segments and correct the error:
Assume that a is a two dimensional array of int values with two rows and two columns.
a [ 1, 1 ] =5;
p[0], p[1], p[2], p[3]
The names of the four elements of an array p are?
declaring
Naming an array, stating its type and specifying the number of elements in the array is called _____ the array.
rows, columns
When accessing an array element, by convention the first subscription in a two-dimensional array identifies and element's ____ and the second subscript identifies the element's ______.
m rows and n columns with n by m elements
An m-by-n array contains ____ rows, ____ columns, and ____ elements.
3-by-5 array
The name of the element in row 3 and column 5 of array d is?
Data Structures
collections of related data items
arrays
data structures consisting of relating data items of the same type, they are static entities in that they remain the same size throughout their life time
size
each array knows its own _____, which can be determined by calling its ____ member function.
name, position number
To refer to a particular location or element in an array, we specify the _____ of the array and the ________ of the particular element in the array.
name, index, [ ]
A program refers to any one of an array's elements by giving the _____ of the array followed by ____ of the particular element in _____.
zero, zeroth
The first element in every array has index _____ and is sometimes called the ______ element.
integer or integer expresssion
An index must be an ____ or _____.
brackets, ( )
The ____ used to enclose the index are an operator with the same precedence as _____.
array< type, arraySize> arrayName;
How do you specify the type of each elements and the number of elements required of an array?
initialized, = , initializer list
the elements of an array can be ______ in the array declaration by following the array with an ______ and _____
initializer list
a common separated list of initializers
<= the array size
the number of initializers must be ?
static
local variable in a function definition exists for the duration of the program but is visible only in the function body
when their declaration are first encountered
When is a static local array initialized?
initialized to zero by the compiler when the array is created
If a static array is not initialized explicitly by you each element of the array is ?
range-based for statment
statement that allows for manipulation of all the elements of an array without using a counter, thus avoiding the possibility of stepping outside the array and eliminating the need for bound checking
for (rangeVariableDeclaration : expression)
statement
syntax of range-based for statment
class varibales
are shared by all objects of the class in which the variables are declared
public static
can be accessed outside of the class, even when no objects of the class exist, using the class name followed by the scope resolution operators and the name of the data member
auto
keyword that can be used in place of a type name to infer the variable's type based on the variable's initializer value
sort
function that sorts and an array's element into ascending order
vector
class template which represents a more robust alternative to arrays featuring many capabilities that are not provided for C-style point-based arrays
vector<type> name( size );
declaration form of a vector
lvalue
an expression that identifies an objects in memory but cannot be used to modify that object, also identifies an object in memory, but can be used to modify the object
exception
indicates a problem that occurs while a program executes
exception handling
enables you to create fault-tolerant program that can resolve exceptions by placing it in a try statement
try block
contains the code that might throw an exception
catch block
contains the code that handles the exception if one occurs, declares a type and exception parameter
terminates
try blocks ___________ when any variables declared in the try block that go out of scope
what method
returns the exception's error message