3. (10 points) Write C++ statement(s) to do the following: a. Declare an array a
ID: 3681052 • Letter: 3
Question
3. (10 points) Write C++ statement(s) to do the following: a. Declare an array alpha of 50 components of type int. b. Initialize each component of alpha to-1 c. Output the value of the first component of d. Set the value of the twenty-fifth component e. Set the value of the tenth component of alpha to three times the value the array alpha. t of the array alpha to 62 of the fiftieth component of alpha plus 10 Use a for loop to output the value of a component of alpha if its index is a multiple of 2 or 3. t. Output the value of the last component of alpha. h. Output the value of the alpha so that 15 components per line are printed i. Use a for loop to increment every other element (the even indexed elements). . Use a for loop to create a new array, diffAlpha, whose elements are the differences between consecutive elements in alpha. 4. (4 points) Suppose that scores is an array of 10 components of type double, and scores2.5, 3.9, 4.8, 6.2, 6.2, 7.4. 7.9, 8.5, 8.5, 9.9 The following is supposed to ensure that the elements of scores are in nondecreasing order. However, there are errors in the code. Find and correct the errors. for (änt i-1; iExplanation / Answer
3)
a) int alpha[50];
b)
for (int i=0;i<50;i++)
{
alpha[i]=-1;
}
c)
cout<<alpha[0];
d)
alpha[24]=62;
e)
alpha[9]=3*alpha[49] + 10;
f)
for (int i=0;i<50;i++)
{
if((i%2 == 0) || (i%3 ==0))
cout<<alpha[i];
}
g)
cout<<alpha[49];
h)
for (int i=0;i<50;i++)
{
if((i==15) || (i==30)||(i==45))
cout<<endl;
cout<<alpha[i];
}
i)
for (int i=0;i<50;i++)
{
if((i%2==0))
alpha[i]++;
cout<<alpha[i];
}
j)
for (int i=0;i<49;i++)
{
diffalpha[i]=alpha[i+1]-alpha[i];
}
4)
the problem is with the loop condition.It will run for i=10 and checking for score[11] which doesn't exist. The for loop condition should be changed to make it work.
for (int i=0;i<9;i++)
5)
a) valid size = 4
b) valid size=10
c) invalid
d)valid size=5
5)
a)valid 4
b)valid 6
c)invalid
d)valid 5
e)valid 5
f)valid 4
6)
d is valid
7)
a is valid
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.