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

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

ID: 657942 • Letter: W

Question

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 twelth 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.

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

// part a

double beta[20];

int i;

// part b

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

beta[i] = 0;

// 5th component means 4th index

cout << "Part C: " << beta[4] << endl;

// part d

beta[8] = 70.50;

// part e

beta[11] = 4*beta[7] - 15;

// part f

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

{

if(i%3 == 0)

cout << beta[i] << " ";

}

// part g

cout << endl << "Last element: " << beta[19] << endl;

// part h

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

{

cout << beta[i] << " ";

if(i==9)

cout << endl;

}

}

/*Output

Part C: 0

0 0 0 0 0 0 0

Last element: 0

0 0 0 0 0 0 0 0 70.5 0

0 -15 0 0 0 0 0 0 0 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