Week 6 Homework Complete the following problems. 1. Write C++ statements to do t
ID: 3627872 • Letter: W
Question
Week 6 HomeworkComplete the following problems.
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?
4. Write C++ statements to define and initialize the following arrays using appropriate data types:
a. An array of heights has 6 components which have the following values: 5.5, 5.8, 6.3, 6.6, 4.9, 5.9.
b. An array of weights has 4 components which have the values: 140, 165, 190, 207.
c. An array of symbols which contains the following characters: '$', '%', '@', '!', '|', '&'.
d. An array of the seasons which contains "Spring", "Summer", "Fall", "Winter".
5. Given the following declaration, what is stored in the 8th element of the array?
int list[10] = {1, 2, 3, 4, 5};
6. When an array is passed as an actual parameter to a function, what is really being passed in to the function? Why are arrays passed this way?
7. Write a for loop to initialize the following array (int data[10]) with the values 10, 9, 8… 1.
8. Given an array of 10 doubles named data, write a loop that loads the array with user input.
9. Given an array of 100 doubles named data, write a loop that creates the sum of all the array elements.
10. Write a loop that finds the smallest element in an integer array called data containing 100 elements.
Explanation / Answer
please rate - thanks
CRAMSTER RULE 1 question per post-to get you started
Week 6 Homework
Complete the following problems.
1. Write C++ statements to do the following:
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.
int i;
alpha[8]=0;
for(i=5;i<13;i++)
alpha[8]+=alpha[i];
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]=alpha[7]*3-57;
f. Output alpha so that five components appear on each line.
int i;
for(i=0;i<15;i++)
{cout<<alpha[i]<<" ";
if((i+1)%5==0)
cout<<endl;
}
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;
}
}
2 7 6 11 10
3. What does array index out of bounds mean? What can happen if this occurs in your program?
the array index is <0 or >= what the array is dimensioned to. you can destroy another variable in memory
4. Write C++ statements to define and initialize the following arrays using appropriate data types:
a. An array of heights has 6 components which have the following values: 5.5, 5.8, 6.3, 6.6, 4.9, 5.9.
double heights[]={5.5, 5.8, 6.3, 6.6, 4.9, 5.9};
b. An array of weights has 4 components which have the values: 140, 165, 190, 207.
int weight[]={140, 165, 190, 207};
c. An array of symbols which contains the following characters: '$', '%', '@', '!', '|', '&'.
char symbols[]={'$', '%', '@', '!', '|', '&'};
d. An array of the seasons which contains "Spring", "Summer", "Fall", "Winter".
string season[]={"Spring", "Summer", "Fall", "Winter"};
5. Given the following declaration, what is stored in the 8th element of the array?
int list[10] = {1, 2, 3, 4, 5};
6. When an array is passed as an actual parameter to a function, what is really being passed in to the function? Why are arrays passed this way? address of the 1st element of the array. because your passing many "variables"
7. Write a for loop to initialize the following array (int data[10]) with the values 10, 9, 8… 1.
for(int i=0;i<10;i++)
data[i]=10-i;
8. Given an array of 10 doubles named data, write a loop that loads the array with user input.
for(int i=0;i<10;i++)
cin>> data[i];
9. Given an array of 100 doubles named data, write a loop that creates the sum of all the array elements.
int sum=0;
for(int i=0;i<10;i++)
sum+=data[i];
10. Write a loop that finds the smallest element in an integer array called data containing 100 elements.
int small=data[0];
for(int i=0;i<100;i++)
if(data[i]<small)
small=data[i];
cout<<"smallest value is "<<small<<endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.