# My Programming Lab - Ch7

int scores;
Declare an array named scores of twenty-five elements of type int.
Write a statement that declares an array of char named streetAddress that contains exactly eighty elements.
We will write a custom essay sample on
My Programming Lab – Ch7
or any similar topic only for you
a 
Given the array a, write an expression that refers to the first element of the array.
a
Given an array a, declared to contain 34 elements, write an expression that refers to the last element of the array.
x = arr[ARR_SIZE-2] ;
Assume that the array arr has been declared. In addition, assume that ARR_SIZE has been defined to be an integer that equals the number of elements in arr .
Write a statement that assigns to x the value of the next to last element of the array ( x has already been declared ).
cout << monthSales;
Assume that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 months of the year in order (i.e., January, February, etc.). Write a statement that writes to standard output the element corresponding to October.
Do not write anything else out to standard output .
a = 3;
Given that an array of int named a has been declared, assign 3 to its first element
salarySteps = 160000;
Assume that an array of integers named salarySteps that contains exactly five elements has been declared .
Write a statement that assigns the value 160000 to the last element of the array salarySteps.
a = 5;
Given that an array of int named a with 30 elements has been declared, assign 5 to its last element
a[k] = 15;
Assume that an array of int named a has been declared with 12 elements and that the integer variable k holds a value between 0 and 6. Assign 15 to the array element whose index is k
a[k-1] = 22;
Given that an array of int named a has been declared with 12 elements and that the integer variable k holds a value between 2 and 8. Assign 22 to the element just before a[k]
a[j] = 2 * a[j+1];
An array of int named a that contains exactly five elements has already been declared and initialized. In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3.
Write a single statement that assigns a new value to the element of the array indexed by j. This new value should be equal to twice the value stored in the next element of the array (i.e. the element after the element indexed by j ). Do not modify any other elements of the array!
Another variable or array will very likely be unexpectedly modified.
Suppose v is an array with 100 int elements. If 100 is assigned to v, what happens?
double taxRates [] = {0.10, 0.15, 0.21, 0.28, 0.31};
Declare an array named taxRates of 5 elements of type double and initialize the elements (starting with the first) to the values 0.10, 0.15, 0.21, 0.28, 0.31, respectively.
int denominations[] = {1, 5, 10, 25, 50, 100};
Write a statement to declare and initialize an array of int named denominations that contains exactly six elements .

Your declaration statement should initialize the elements of the array to the following values: 1, 5, 10, 25, 50, 100. (The value 1 goes into the first element; the value 100 to the last.)

for(total = 0, k = 0; k < n; k++) total += temps[k]; avgTemp = total / n;
Given an array temps of double, containing temperature data, and an int variable n that contains the number of elements in temps :
Compute the average temperature and store it in a variable called avgTemp .
Besides temps, n, and avgTemp, you may use only two other variables — an int variable k and a double variable total, which have been declared.
printArray(inventory, n);
printArray is a function that has two parameters. The first parameter is an array of element type int and the second is an int, the number of elements in the array. The function prints the contents of the array parameter; it does not return a value.
inventory is an array of int s that has been already declared and filled with values. n is an int variable that holds the number of elements in the array .
Write a statement that prints the contents of the array inventory by calling the function printArray
void printArray(int[], int);
Write a statement that declares a prototype for a function printArray, which has two parameters. The first parameter is an array of element type int and the second is an int, the number of elements in the array. The function does not return a value.
void printArray(int s[], int m){
int n;
for(n = 0; n< m; n++) cout << s[n] << endl; }
Write the definition of a function printArray , which has two parameters. The first parameter is an array of int s and the second is an int, the number of elements in the array. The function does not return a value. The function prints out each element of the array, on a line by itself, in the order the elements appear in the array, and does not print anything else.
int sumArray(int a[], int n){
int index;
int sum = 0;
for(index = 0; index < n; index++) sum += a[index]; return sum; }
Write the definition of a function named sumArray that receives two parameters: an array of element type int and an int that contains the number of elements of the array. The function returns the sum of the elements of the array as an int.
const int SIZE = 8;
string chessboard[SIZE][SIZE];
Declare a 8×8 two-dimensional array of strings named chessboard.
const int row = 3;
const int column = 10;
int arr[row][column];
Declare a two-dimensional array of integers named arr with 3 rows and 10 columns.
x + x
Given a two-dimensional array x of element type int, write an expression whose value is the sum of the element in the 3rd row/4th column and the element in the 5th row/1st column
x
Given a two-dimensional array x of element type int with 5 rows and 4 columns, write an expression whose value the last element in the array (the last column of the last row).
x[i][j]
Given a two-dimensional array x of element type double, and two integer variables i and j, write an expression whose value is the i-th element in the j-th row.
for (int i = 0; i < 2; i++){ for (int k = 0; k <4; k++) { q[i][k] = 0; } }
Given a two-dimensional array of integers named q, with 2 rows and 4 columns, write some code that puts a zero in every element of q. Declare any variables needed to help you.
max = x;
for(int i = 0; i < 6; i++){ for (int j = 0; j < 8; j++){ if(x[i][j] > max)
max = x[i][j];
}
}
You are given a 6×8 (6 rows, 8 columns) array of integers, x, already initialized and three integer variables: max, i and j. Write the necessary code so that max will have the largest value in the array x.
int westboundHollandTunnelTraffic;
Declare an array of integers, westboundHollandTunnelTraffic that can store the number of vehicles going westbound through the Holland Tunnel on a particular hour (numbered 0 through 23) on a particular day (numbered 0 through 6) on a particular week numbered (0 through 51) over the last ten years (numbered 0 through 9). The innermost dimension should be years, with the next being weeks, and so on.
int countMatches(int custPIN[], int databasePIN[], int size) {
int matches = 0;
for (int index = 0; index < size; index++) { if (custPIN[index] == databasePIN[index]) matches++; } return matches; }
Consider the testPIN function used in Program 7-21. For convenience, we have reproduced the code for you below. Modify this function as follows:change its type to int change its name to countMATCHES make it return the number of corresponding parallel elements that are equal.
bool testPIN(int custPIN[], int databasePIN[], int size)
{
if (countMatches(custPIN, databasePIN, size)== size)
return true;
else
return false;
}
Again, consider the testPIN function used in Program 7-21. For convenience, we have reproduced the code for you below.Rewrite the function body of this function so that instead of using iterating through the elements of the parallel arrays, it returns true or false by calling countMatches the function defined in the previous exercise (10988), and checking its return value.

#### New Essays

×

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