Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (TCO 11) If n represents the size of an array, what would be the index of the

ID: 3543341 • Letter: 1

Question

1. (TCO 11) If n represents the size of an array, what would be the index of the last element in the array? (Points : 3)       n-2
      n
      n-1
      Cannot be determined

2. (TCO 11) Which of the following techniques can be used to process the elements of a multidimensional array? (Points : 3)       Nested selection structure
      Nested looping structure
      Sequence structure
      None of the above

3. (TCO 11) A five-row, six-column array has a total of how many elements? (Points : 3)       1
      36
      30
      11

4. (TCO 12) Given the following array:

int profit [5] = {10, 20, 31, 55, 66};

The following statement would replace which value?
profit [0] = profit[2]; (Points : 3)       10 with 31
      10 with 20
      20 with 31
      10 with 55

5. (TCO 12) What is the character automatically included at the end of an array of characters? (Points : 3)       
      
      z
      *

6. (TCO 11) In the following table, what is the value of table[2][1]?
int table[3][4]={3,7,0,2,4,9,8,1,3,6,5,4};
(Points : 3)       4
      7
      6
      1

7. (TCO 11) What type of error will this code produce?

int n[30], i;
for(i = 0; i <= 30; ++i)
     n[i] = i; (Points : 3)       No compiler errors will be reported.
      A compiler error is generated since there are no braces {} with the for loop.
      A runtime error may occur because we are out of bounds on the array.
      No compiler errors will be reported, but a runtime error may occur because we are out of bounds on the array.


8. (TCO 11) Is it possible to write code in this manner for a C++ program?

int break;
cout << "What time is your break?";
cin >> break;
int numbers[break]; (Points : 3)       Yes, this is perfectly acceptable C++ code.
      No, the array dimension cannot be a variable.
      The compiler would report that there is an illegal use of a keyword.
      Yes, this is perfectly acceptable C++ code, but the compiler would report that there is an illegal use of a keyword.


9. (TCO 11) What is wrong with this code?

void WriteDay(char d[]);
int main( )
{
     char Day [10] = "Friday";
     WriteDay(Day[]);
     return 0;
} (Points : 3)       The brackets are not needed in the call statement.
      Friday is too short for the array.
      The code is correct as written.
      The call statement should be written as WriteDay(Day[10]);

10. (TCO 12) Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of element 3 of the array? (Points : 3)       *( tPtr + 3 )
      tPtr[ 3 ]
      &t[ 3 ]
      *( t + 3 )

11. (TCO 11) Explain how to declare and assign values to a two-dimensional array and provide a C++ program segment that illustrates your answer. Provide a summary of how the values are stored. (Points : 5) 11. (TCO 11) Explain how to declare and assign values to a two-dimensional array and provide a C++ program segment that illustrates your answer. Provide a summary of how the values are stored. (Points : 5) 1. (TCO 11) If n represents the size of an array, what would be the index of the last element in the array? (Points : 3)       n-2
      n
      n-1
      Cannot be determined

Explanation / Answer

1. For an array of size n, Array indexing starts at 0. So the first element will be stored at index1, second element at index 2 and so on. The last element will be stored at index n-1.

2. The elements of a multi-dimensional array can be processed by using nested looping structure.

3. An array declared as 5 rows and 6 columns will have a total of 30 elements. It represents a 5X6 matrix.

4. In the array given, profit[] is initialized at the time of declaration. So initially profit [0] =10 and profit[1]=20, profit[2]=31. After the statement profit [0] =profit [2], profit [0] will have the value 31.

5. An array of characters is called a string. Every string is terminated by the null character at the end.

6. In multidimensional arrays, indexing of the elements starts at 0. Table [2][1] indicates that the element is in the 3rd row 2nd column. 6 represents the element table[2][1].

7. No complier error will be reported.

8. It is possible to create an array with a size the user inputs.

9. The code is correct

10. An array is t and tptr is a pointer to array t. Initially tptr will have the address of the first element of the array i.e. element at index 0. &t [3] will give the address of the third element of the array.

11. A two-dimensional array can be declared as follows.

type arrayName [size][size];

Suppose a integer matrix of size 3 X 4 is to declared. It can be done as follows:

int mat[3][4];

An two-dimensional array can also be initialized at the time of declaration.

int a[5][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8}};