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

Please Complete in C++ language 1. Assume an array called AR contains 45 integer

ID: 3705514 • Letter: P

Question

Please Complete in C++ language

1. Assume an array called AR contains 45 integers. Write a loop to print out the values of every other integer starting from subscript 0. 2. Assume an array called AR contains 10 integers. Write code to swap the very first and the very last values in the array. 3. Declare an array to hold 500 integers. In the declaration statement, initialize the array so the very first value is 2, the second is 4, and all the rest are 0. 4. Write a function to cube the first N elements in an array of doubles. The function should be passed the array and the number of elements to be cubed. It returns nothing. 5. Write a function to return the sum of the first N elements in an array of doubles. The function can assume N >= 0. The function should be passed the array and the number of elements to be added together.

Explanation / Answer

Ques 1.

int i;

// n is the length of AR

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

    cout<<AR[i]<<" ";

Ques 2.

// n is the length of AR

int temp = AR[0];

AR[0] = AR[ n - 1 ];

AR[ n - 1 ] = temp;

Ques 3.

int AR[500] = { 2 , 4 , 0 };

Ques 4.

void cube(double AR[], int n)

{

    int i;

   

    // traverse first n elements of AR

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

        // calculate the cube of the current element

        AR[i] = AR[i] * AR[i] * AR[i];

}

Ques 5.

double getSum(double AR[], int n)

{

    int i;

   

    double sum = 0.0;

   

    // traverse first n elements of AR

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

        sum += AR[i];

   

    return sum;

}