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

Please provide answers within the C++ language. Thank you so much for your help!

ID: 3599722 • Letter: P

Question

Please provide answers within the C++ language. Thank you so much for your help!

1. Declare an array named AR to hold 4 integers and fill it with the numbers 2, 4, 6, and 8.

2. Assume an array called AR contains 4 integers. Write a loop to print out the values of the 4 integers.

3. Assume an array called AR contains 4 integers. Write code to exchange the very first and the very last values in the array.

4. Declare an array named AR to hold 1000 integers. In the declaration statement, initialize the array so the very first value is 10, the second is 20, and all the rest are 0.

5. Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _____ to ______.

6. Complete the following sentence: the unsubscripted name of an array is _______________________________.

7. Write code to swap element [2] and element [4] in an array of floats called AR. Declare a simple variable called temp for this question, and assume the array is correctly declared and initialized.

8. Write code to copy the 0th element of an array called AR into all the other elements of the array. Assume there are 10 elements in the array.

9. Complete the following sentence: all the elements of an array must be the same ____________.

10. True or false: ALL of the declared elements in an array MUST be initialized and used.

11. Write a function called squareAr that squares the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be squared (N). The function returns nothing.

12. Write a function called calcAvg that calculates and returns the average of the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be use in the calculation (N). The function returns a double: the calculated average. The function can assume N >= 0.

Explanation / Answer

1. Declare an array named AR to hold 4 integers and fill it with the numbers 2, 4, 6, and 8.
Answer: int AR[] = { 2,4,6,8 };

2. Assume an array called AR contains 4 integers. Write a loop to print out the values of the 4 integers.
Answer: for (int i=0;i<4;++i)
cout <<AR[i] <<" ";

3. Assume an array called AR contains 4 integers. Write code to exchange the very first and the very last values in the array.

int temp = AR[3];
AR[3] = AR[0];
AR[0] = temp;

4. Declare an array named AR to hold 1000 integers. In the declaration statement, initialize the array so the very first value is 10, the second is 20, and all the rest are 0.
int AR[1000] = {0};
AR[0] = 10;
AR[1] = 20;

5. Complete the following sentence: If you declare an array to hold N values, legal subscripts run from __0___ to __N-1____.

6. Complete the following sentence: the unsubscripted name of an array is __the address of array_______

7. Write code to swap element [2] and element [4] in an array of floats called AR. Declare a simple variable called temp for this question, and assume the array is correctly declared and initialized.

float temp = AR[2];
AR[2] = AR[4];
AR[4] = temp;

8. Write code to copy the 0th element of an array called AR into all the other elements of the array. Assume there are 10 elements in the array.
for (int i=1;i<10;++i)
AR[i] = AR[0];

9. Complete the following sentence: all the elements of an array must be the same TRUE.

10. True or false: ALL of the declared elements in an array MUST be initialized and used. : FALSE

11. Write a function called squareAr that squares the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be squared (N). The function returns nothing.

void squareAr(double a[] , int n) {

for (int i = 0 ; i<n ; ++i){

a[i] = a[i]*a[i];
}

}

12. Write a function called calcAvg that calculates and returns the average of the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be use in the calculation (N). The function returns a double: the calculated average. The function can assume N >= 0.

void calcAvg(double a[] , int n) {

double sum = 0;
for (int i = 0 ; i<n ; ++i){

sum = sum + a[i];
}
return sum/n;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote