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

Please comment this code line by line: #include <iostream> #include <iomanip> #i

ID: 643902 • Letter: P

Question

Please comment this code line by line:

#include <iostream>
#include <iomanip>
#include "time.h"

using namespace std;

void rowSum(int anArray[][10], int nmbrRows, int nmbrClmns)
{

//sums the elements of a two-dimensional array

int sum = 0;

for (int row = 0; row < nmbrRows; row++)
{

sum = 0;
for (int clmn = 0; clmn < nmbrClmns; clmn++)
sum += anArray[row][clmn];
cout << setw(3)<< row << setw(3) << sum << endl;

}
}

int main()
{

srand((unsigned int)time(NULL));
int a[3][5];

for (int i=0; i<3; i++)
{

for(int j=0; j<5; j++)
{

a[i][j] = rand()%101;
cout << setw(4) << a[i][j];

}
cout << endl;
}

return 0;

}

Explanation / Answer

#include

//this line is used to include header file iostream.h

#include

//this line is used to include header file iomanip.h

#include "time.h"

//this line is used to include header file time.h

using namespace std;

//this line is used to include namespace std

//this line is used to add a method called rowSum

void rowSum(int anArray[][10], int nmbrRows, int nmbrClmns)
{

//sums the elements of a two-dimensional array

int sum = 0;

//this for loop is used to add and display sum using manipulators

for (int row = 0; row < nmbrRows; row++)
{

sum = 0;
for (int clmn = 0; clmn < nmbrClmns; clmn++)
sum += anArray[row][clmn];
cout << setw(3)<< row << setw(3) << sum << endl;

}
}

int main()

//this line is used to start the program
{

//this line is used to call function srand with uint and time as parameter

srand((unsigned int)time(NULL));

//this line is used to declare 2 dimensional array
int a[3][5];

//these for loops are used to fill data in array and display it

for (int i=0; i<3; i++)
{

for(int j=0; j<5; j++)
{

a[i][j] = rand()%101;
cout << setw(4) << a[i][j];

}
cout << endl;
}

//this line is used to reture zero value

return 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