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: 3543344 • 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

Dear,

1) Array index starts from 0 and the last element index is n-1.
2) Nested looping structure methodology is used to process multidimensional array.
3) Total number of elements in an two dimensional array is rows*cols
     i.e 5-row 6-col array has 30 elements.
4)This statemenet profit [0] = profit[2]; will update first with 3rd value 31.
   10 with 31.
5)'' represents null or end character which is automaically included as last index value
   in array.
6) int table[3][4]={3,7,0,2,
                    4,9,8,1,
                    3,6,5,4};
    table[2][1]represents last rows second value i.e 6.
7)No compiler errors will be reported.
8)The compiler would report that there is an illegal use of a keyword.
9)When passing an array we can just pass array name. therefore "The brackets are not needed in the call statement."
10) *( tPtr + 3 ) refers to accessing third element in array using pointer.


Hope this will help you...