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

help solve please and thank you For each of the given program segments, determin

ID: 3554956 • Letter: H

Question

help solve please and thank you

For each of the given program segments, determine if there is an error in the code, circle the error in the program and write the corrected code in the space provided after each problem. If the code does not contain an error, write "no error". Note: it is possible that a program segment may contain multiple errors. The for loop should initialize all array value to -1. Array array should contain all the integers from 0 through 10. inclusive. The following code segment should declare two arrays containing five and six elements, respectively: For each of the given program segments, read the code and write the output in the space provided below each program.

Explanation / Answer

1. int array[10];
// in BELOW LINE i<=9 is correct code
for(int i=0; i<=9; i++)
array[i] = 1;

// in BELOW LINE length of array should be 11.
2. int array[11] = {0,1,2,3,4,5,6,7,8,9,10};

3. const int arraySize =5;  
   int a[arraySize];
   // BELOW LINE IS WRONG U CANT CHANGE Value of CONST VARIABLE.
   //arraySize = 6;

   int b[arraySize+1];
  
4. int i;
   int values[10] = {4,1,1,3,4,9,9,2,1,7};
   cout << "Element" << setw(13) <<"Value "<< endl;
   for(int i=0; i<10; i++)
   cout << setw(7) << i << setw(13) << values[i] << endl;

/* OUTPUT
Element       Value
      0            4
      1            1
      2            1
      3            3
      4            4
      5            9
      6            9
      7            2
      8            1
      9            7
*/

#include<iostream>
using std::cout;
using std::endl;
void mystery();
int main()
{
cout <<"First call to mystery " << endl;
mystery();
cout <<" Second call to mystery " << endl;
mystery();
cout << endl;
return 0;
}

void mystery()
{
static int array1[3];
int i;
cout<<" Values on entering mystery: ";
for(i=0; i<3; i++)
cout <<"array1[" << i << "] = " <<array1[i] << " ";
cout<<" Values on exiting mystery: ";
for(i=0; i<3; i++)
cout <<"array1[" << i << "] = " <<(array1[i]+=2) <<" ";
}

/* OUTPUT
First call to mystery


Values on entering mystery:
array1[0] = 0 array1[1] = 0 array1[2] = 0
Values on exiting mystery:
array1[0] = 2 array1[1] = 2 array1[2] = 2
Second call to mystery


Values on entering mystery:
array1[0] = 2 array1[1] = 2 array1[2] = 2
Values on exiting mystery:
array1[0] = 4 array1[1] = 4 array1[2] = 4
*/