Computer Programming Chapter 7 function

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.
What is the difference between a size declarator and a subscript?
10 elements
Subscript of the 1st element is zero
Subscript of the last element is 9
The array used 40 bytes of memory
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?
We will write a custom essay sample on
Computer Programming Chapter 7 function
or any similar topic only for you
Order now
Because, with the array alone the function has no way of determining the number of elements it has.
Why should a function that accepts an array as an argument, and processes that array, also accept an argument specifying the arrays size?
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
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; __________
By providing an initialization list. The array is sized to hold the number of values in the list.
How do you define an array without providing a size declarator?
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
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]?
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.
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;
reference
Is an array passed to a function by value or by reference?
Passing array name to function will pass address of array of integers
When you pass an array name as an argument to a function, what is actually being passed?
By using the same subscript value for each array.
How do you establish a parallel relationship between two or more arrays?
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
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
The second size declarator, which is for the number of columns.
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?
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
What advantages does a vector offer over an array?
size declarator
The _________ indicates the number of elements, or values, an array can hold.
Integer with a value greater than zero
The size declarator must be a(n) _________ with a value greater than _________.
subscript
Each element of an array is accessed and indexed by a number known as a(n)_________.
Zero
Subscript numbering in C++ always starts at _________.
size declarator, subscript
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 _________.
Bounds
C++ has no array _________ checking, which means you can inadvertently store data past the end of an array.
initialization
Starting values for an array may be specified with a(n) _________ list.
Zero
If an array is partially initialized, the uninitialized elements will be set to _________.
initialization list
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.
Subscript
By using the same _________ for multiple arrays, you can build relationships between the data stored in the arrays.
=
You cannot use the _________ operator to copy data from one array to another in a single statement.
Array’s beginning memory address
Any time the name of an array is used without brackets and a subscript, it is seen as _________.
address, or name
To pass an array to a function, pass the _________ of the array.
Two-dimensional
A(n) _________ array is like several arrays of the same type put together.
rows and columns
Its best to think of a two-dimensional array as having _________ and _________.
TWO
To define a two-dimensional array, _________ size declarators are required
braces []
When initializing a two-dimensional array, it helps to enclose each row s initialization list in _________.
Column
When a two-dimensional array is passed to a function the _________ size must be specified.
Standard Template Library (or STL)
The ____________________ is a collection of programmer-defined data types and algorithms that you may use in your programs
Sequence container and associative container
The two types of containers defined by the STL are ___________ and______________.
sequence
The vector data type is a(n) ______________ container
To define a vector in your program, you must #include the ____________ header file.
push_back
To store a value in a vector that does not have a starting size, or that is already full, use the ________________ member function.
size
To determine the number of elements in a vector, use the _____________ member function.
pop_back
Use the ________________ member function to remove the last element from a vector.
Clear
To completely clear the contents of a vector, use the ___________ member function.
To calculate the amount of memory used by an array, multiply the number of elements by the number of bytes each element uses.
Literal or named constant
The individual elements of an array are accessed and indexed by ______.
You can write programs that use invalid subscripts for an array.
The values in an initialization list are stored in the array in the order they appear in the list.
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.
Its best to think of two-dimensional arrays as having rows and columns.
If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value.
The size declarator cannot be negative.
int collection[-20];
For the array to be implicitly sized there must be an initialization list.
float ratings[];
The assignment operator cannot be used to assign the contents of one array to another, in a single statement
int array1[4], array2[4] = {3, 6, 9, 12};
array1 = array2;
The parameter must specify the number of columns, not the number of rows.
void showValues(int nums[4][])
{
for (rows = 0; rows < 4; rows++) for (cols = 0; cols < 5; cols++) cout << nums[rows][cols]; }
const int size = 20;
for(int i = 0; i < size; i++) cout << names[i] << endl;
names is an integer array with 20 elements.
Write a for loop that prints each element of the array.
const int size = 100;
for(int i = 0; i < size; i++) numberArray1[i] = numberArray2[i];
The arrays numberArray1 and numberArray2 have 100 elements. Write code that
copies the values in numberArray1 to numberArray2.
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; }
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.
int ID[10];
double Emp[10];
Define two arrays that may be used in parallel to store the 10 ID numbers and gross pay amounts.
int grades[30][10];
Define a two-dimensional array of integers named grades.
It should have 30 rows and 10 columns.
int numberArray[0][0] = 145;
int numberArray[8][10] = 18;
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 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]

Write code that sums all the elements in the array and stores the sum in the variable total
vector frogs;
Write a definition statement for a vector named frogs . frogs should be an empty vector of int s.
vector gators;
gators.push_back(27);
gators is an empty vector of int s. Statement that stores the value 27 in gators .
×

Hi there, would you like to get such a paper? How about receiving a customized one? Check it out