1. Write C++statement(s) to do the following: a. Declare an array of 50 componen
ID: 3708596 • Letter: 1
Question
1. Write C++statement(s) to do the following: a. Declare an array of 50 components of type int b. Initialize each component of alpha to -1 c. Output the value of 3"d component of alpha d. Set the value of the 25th component to 62 e. Set the value of the 10 component of alpha to three times the value of the 50h component of alpha plus 10 f. Use a for loop to output the value of component of alpha if its index is a multiple of 2 or 3. g. Output the value of last component of alpha h. Output the value of alpha so that 15 components per line i. Use a for loop to increment the values of every other j. Create a new array diffAlpha, whose elements are are printed element (even numbered index) by 1 differences between consecutive elements in alpha. What is the size of diffAlpha?Explanation / Answer
C++ statements for the follwing:
a. int alpha[50];
b. for (int i=0;i<50;i++)
{
alpha[i]=-1;
}
c. cout<<alpha[2]; //2, because index starts from zero
d. alpha[24] = 62; //24, because index starts from zero
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]; //49, because index starts from zero
h.
for (int i=0; i<50; i++)
{
cout<<alpha[i]<<" ";
if ( i % 14 == 0 ) //14, because index starts from zero
cout<<endl; //displays new line only when i is multiples of 14 (add newline after displaying 15 aplhas)
}
i. for(index=0;index<50;index=index+2)
{
alpha[index]=alpha[index]+1;
}
//Only the values of even indexed component are incremented by 1
j. int diffalpha[49]; //creating new array
for(index=0;index<49;index++)
{
diffalpha[index]=alpha[index]-alpha[index+1]:
}
The size of diffAlpha is 49. Because, for 50 elements, you can only calculate 49 consecutive differences.
-----------------------------------------------------------------------------------------------------------------------------------------------
Please upvote if you are happy with the answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.