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

Introductory21.cpp. The program should calculate and display the average of the

ID: 3777892 • Letter: I

Question

Introductory21.cpp. The program should calculate and display the average of the values stored in the rates array. Display the average with two decimal places. Complete the program using the for statement. This is what I have so far.

//Introductory21.cpp - calculates and displays the
//average rate stored in a two-dimensional array

#include <iostream>

#include <iomanip>
using namespace std;

int main()
{
   double rates[5][3] = {{3.4, 56.7, 8.99},
                       {11.23, 4.67, 85.4},
                      {34.6, 2.4, 9.0},
                       {6.3, 8.0, 4.1},
                       {4.0, 2.0, 3.5}};


   return 0;
}   //end of main function

Explanation / Answer

//Introductory22.cpp - displays the contents of a
//two-dimensional array, column by column and row by row
//Created/revised by <your name> on <current date>

#include <iostream>

using namespace std;

int main()
{
int nums[2][4] = {{17, 24, 86, 35},
{23, 36, 10, 12}};
int i=0,j=0;
//display column by column
cout<<"Printing column by column ";
while(j<4){
           for (i = 0; i < 2; i++) {
           cout<<nums[i][j]<<" ";
   }
   cout<<endl;
   j++;
       }
cout << endl;
//display row by row
cout<<"Printing row by row ";
i=0;//resetting i to 0
while(i<2){
for(j=0;j<4;j++){
cout<<nums[i][j]<<" ";
}
cout<<endl;
i++;
}
return 0;
}

----------------output------------------
Printing column by column   
17 23   
24 36   
86 10   
35 12
Printing row by row   
17 24 86 35
23 36 10 12
----------------output ends------------------

Note: Feel free to ask question. God bless you!!

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