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

1. Write C++ statements to do the following: a. Declare an array alpha of 15 com

ID: 3629941 • Letter: 1

Question

1. Write C++ statements to do the following:

a. Declare an array alpha of 15 components of type int.
b. Output the value of the 10th component of the alpha array.
c. Set the value of the 5th component of the alpha array to 35.
d. Set the value of the 9th component of the alpha array to the sum of the 6th and 13th components of the alpha array.
e. Set the value of the 4th component of the alpha array to three times the value of the 8th component minus 57.
f. Output alpha so that five components appear on each line.

2. What is stored in the list array after the following code executes?

int list[5];
for(int j = 0; j < 5; j++)
{
list[j] = 2 * j + 5;
if (j % 2 == 0)
{
list[j] = list[j] - 3;
}
}

3. What does array index out of bounds mean? What can happen if this occurs in your program?

Explanation / Answer

a. Declare an array alpha of 15 components of type int.
int alpha[15];

b. Output the value of the 10th component of the alpha array.
cout << alpha[9];

c. Set the value of the 5th component of the alpha array to 35.
alpha[4] = 35;
d. Set the value of the 9th component of the alpha array to the sum of the 6th and
13th components of the alpha array.
alpha[8] = alpha[5] + alpha[12];
e. Set the value of the 4th component of the alpha array to three times the value of the 8th component minus 57.
alpha[3] = 3*alpha[7] - 57;
f. Output alpha so that five components appear on each line.
for(int i=0; i<15; i++)
{
if(i%5 ==0)
cout << endl;
cout << alpha[i];
}

2) 2 7 6 11 10

3) index out of bounds menas you are trying to access value from which may or may nor exist.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote