1/63
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Simple Data Type
variables of this type can store only one value at a time
Structured Data Type
a data type in which each data item is a collection of other data items
Array
a collection of a fixed number of components
One Dimensional Arrays
components are arranged in list form
Syntax for declaring one dimensional arrays
dataType arrayName [intExp];
intExp
any constant expression that evaluates into a positive integer
General Syntax for accessing array elements
arrayName[indexExp]
indexExp
called the index (an integer with a nonnegative integer value)
Basic Operations of a one-dimensional array
Initializing, Inputting Data, Outputting data stored in an array, Finishing the largest and or smallest element
Index of an array
is in bounds if the index is >= 0 and <= ARRAY_SIZE -1
Out of bounds index
the index is out of bounds if it does not meet the criteria of being in bounds
Array Initialization during Declaration
Arrays can be initialized during declaration with values placed between curly braces
Partial Initialization of Arrays during Declaration
Size determined by the number of initial values in braces
Aggregate Operation
any operation that manipulates the entire array as a single unit, not allowed on arrays in C++
Arrays as Parameters to Functions
Arrays are passed by reference only
Constant Arrays as Formal Parameters
They can prevent a function from changing the actual parameter when passed by reference
Base Address of an Array
address (memory location) of the first array component
Functions cannot return a value of the type Array
C++ does not allow functions to return a value of type array
Integral Data Types and Array Indices
C++ allows any integral type to be used as an array index
Sequential Search
Searching a list for a given item, starting from the first array element
Selection Sort
rearrange the list by selecting an element and moving it to its proper position
Character Array
an array whose components are of type char
C-Strings
null-terminated ('\0') character arrays
Example of C-Strings
'A' is the character A; "A" is the c-string A; "A" represents two characters: 'A' and '\0'
Maximum string length in C-Strings
the largest string it can store is 15 characters if it has 16 components
Omitting size of an array during initialization
Size of an array can be omitted if the array is initialized during declaration
strcpy
Function used to copy a string.
strcmp
Function used to compare two strings.
strlen
Function used to determine the length of a string.
C-Strings
Character arrays that are null-terminated.
ASCII character set comparison
Character strings are compared using the ASCII values, e.g., 'Air' < 'Boat'.
cin >> name
Reads the next input c-string into the variable name.
cin.get(str, m+1)
Reads the next m characters into str, excluding the newline character.
cout << name
Outputs the content of name to the screen.
Null character
Character that indicates the end of a c-string.
c_str function
Converts a string variable to a c-string.
Parallel arrays
Two or more arrays that hold related information.
Two-dimensional arrays
Collections of components arranged in rows and columns.
Declaration syntax for two-dimensional arrays
dataType arrayName [intExp1][intExp2].
Accessing components in a two-dimensional array
arrayName[indexExp1][indexExp2] where indexExp1 and indexExp2 specify row and column.
Sales[5][3]
Example of accessing a component in a two-dimensional array.
Two-dimensional array initialization
Can be initialized at declaration with elements enclosed in braces.
Unspecified elements in number arrays
Are set to 0 when not explicitly initialized.
Two-dimensional array
A structured data type with a fixed number of components of the same type, arranged in a table form.
Row processing
Processing a two-dimensional array one row at a time.
Column processing
Processing a two-dimensional array one column at a time.
One-dimensional array
An array where elements are arranged in the form of a list.
Base address
The address of the first array component.
Passing two-dimensional arrays
Two-dimensional arrays are passed by reference as parameters to a function.
Row order storage
Two-dimensional arrays are stored in row order.
Array of strings
A collection of strings that can be manipulated using either the string data type or character arrays (c-strings).
Declaration of array of strings
To declare an array of 100 components of type string: string line[100].
N-dimensional array
A collection of a fixed number of elements arranged in n dimensions (n >= 2).
Declaration syntax for multidimensional arrays
dataType arrayName[intExp1][intExp2]... [intExp];
Accessing a component
To access a component: arrayName[index1][index2]...[indexEspn].
Array index
An expression that evaluates to a nonnegative integer, must always be less than the size of the array.
Function return for arrays
A function cannot return an array type value.
C-strings
C-strings are null terminated and are stored in character arrays.
Common c-string functions
Commonly used c-string manipulation functions include: strcpy, strcmp, strlen.
Parallel arrays
Arrays used to hold related information.
Accessing elements in two-dimensional arrays
To access an element, you need a pair of indices: one for row position, one for column position.
Sum by row
Calculating the total of each row in a two-dimensional array.
Sum of column
Calculating the total of each column in a two-dimensional array.
Largest element in each row and column
Finding the largest element for every row and every column in a two-dimensional array.