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

3. Write C++ statements to do the following: a. Declare an array beta of 20 comp

ID: 3844186 • Letter: 3

Question

3. Write C++ statements to do the following:

a. Declare an array beta of 20 components of type double.

b. Initialize each component of the array beta to 0.

c. Output the value of the fifth component of the array beta.

d. Set the value of the ninth component of the array beta to 70.50.

e. Set the value of the twelfth component of beta to four times the value of the eighth

component of beta minus 15.

f. Use a for loop to output the value of a component of beta if its index is a multiple of 3.

g. Output the value of the last component of beta.

h. Output the value of beta so that ten components per line are printed.

4. What is stored in myList after the following C++ code executes?

double myList[5];

myList[0] = 3.0;

myList[1] = 4.0;

for(int i = 2; i < 5; i++)

{

myList[i] = myList[i - 1] * myList[i - 2];

if (i > 3)

myList[i] = myList[i] / 4;

}

Explanation / Answer

3.

a. double beta[20];

b. for(int i=0; i < 20; i++) {

            beta[i] = 0;

    }

c. cout<<beta[4];

d. beta[8] = 70.50;

e. beta[11] = 4*beta[7] – 15;

f. for(int i=0; i < 20; i++) {

            if(i%3 == 0) {

                        cout<<beta[i];

            }

   }

g. int size=sizeof(beta)/sizeof(beta[0]);

    cout<<beta[size-1];

h. for(int i=0; i < 20; i++) {

            if(i< 10) {

                        cout<<beta[i]<<” ”;

            } else if(i == 10) {

                        cout<<” ”<<beta[i]<<” “;

             } else {

                        cout<<beta[i]<<” ”;

             }

   }

4.

myList will have 5 elements that are 3.0,4.0,12.0, 12.0, 36.0

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