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

1) Declare an array named a of 10 elements of type int and initialize the elemen

ID: 3633719 • Letter: 1

Question

1) Declare an array named a of 10 elements of type int and initialize the elements (starting with the first) to the values 10, 20, ..., 100, respectively.

2) Declare an array named taxRates of 5 elements of type double and initialize the elements (starting with the first) to the values 0.10, 0.15, 0.21, 0.28, 0.31, respectively.

3) Write a statement to declare and initialize an array of int named denominations that contains exactly six elements.

Your declaration statement should initialize the elements of the array to the following values: 1, 5, 10, 25, 50, 100. (The value 1 goes into the first element; the value 100 to the last.)

4) Assume that an array of integers named a that contains exactly five elements has been declared and initialized.


Write a single statement that assigns a new value to the first element of the array. This new value should be equal to twice the value stored in the last element of the array.


Do not modify any values in the array other than the first element.

5) Given an array temps of double , containing temperature data, and an int variable n that contains the number of elements in temps :

Compute the average temperature and store it in a variable called avgTemp .

Besides temps , n , and avgTemp , you may use only two other variables -- an int variable k and a double variable total , which have been declared.

6) We informally define the term "corresponding element" as follows: The first element in an array and the last element of the array are corresponding elements. Similarly, the second element and the element just before the last element are corresponding elements. The third element and the element just before the element just before the last element are corresponding elements -- and so on.


Given an array a and a variable n that contains the number of elements in a , write an expression for the corresponding element of a[i] .


Explanation / Answer

Dear,

As you didn't mention programming language we are assuming it is in C++

/*1) Declare an array named a of 10 elements of type int and initialize

      the elements (starting with the first) to the values

      10, 20, ..., 100, respectively.*/

      int a[10]={10, 20, 30,40,50,60,70,80,90,100};

      /*2) Declare an array named taxRates of 5 elements of type double and

      initialize the elements (starting with the first) to the values

      0.10, 0.15, 0.21, 0.28, 0.31, respectively.*/

      double taxRates[5]={0.10, 0.15, 0.21, 0.28, 0.31};

      /*3) Write a statement to declare and initialize an array of int named

      //denominations that contains exactly six elements.

      //

      //Your declaration statement should initialize the elements of

      //the array to the following values: 1, 5, 10, 25, 50, 100.

      //(The value 1 goes into the first element; the value 100 to the last.)*/

      int denominations[6]={1, 5, 10, 25, 50, 100};

      /*4) Assume that an array of integers named a that contains exactly

      five elements has been declared and initialized.

      Write a single statement that assigns a new value to the first

      element of the array. This new value should be equal to

      twice the value stored in the last element of the array.*/

      a[0]=a[4]*2;

      /*5) Given an array temps of double , containing temperature data,

      and an int variable n that contains the number of elements in temps :

      Compute the average temperature and store it in a variable called avgTemp .

      Besides temps , n , and avgTemp , you may use only two other variables --

      an int variable k and a double variable total , which have been declared.

      */

      total=0;

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

      {

           total +=temps[k];

      }

      avgTemp=total/n;

      /*6) We informally define the term "corresponding element" as follows:

      The first element in an array and the last element of the array are

      corresponding elements. Similarly, the second element and the element

      just before the last element are corresponding elements. .

      The third element and the element just before the element just before

      the last element are corresponding elements -- and so on.

      Given an array a and a variable n that contains the number of elements in a ,

      write an expression for the corresponding element of a[i] .*/

      for(int i=0,j=n-1;i<=j;i++,j--)

      {

           cout<<"The corresponding element of "<<a[i]<<" is "<<a[j]<<endl;

      }

Hope this helps you