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

Using C/C++, define a two-dimensional integer array with 5 rows and 5 columns (e

ID: 3795527 • Letter: U

Question

Using C/C++, define a two-dimensional integer array with 5 rows and 5 columns (e.g. random numbers between 10 and 100 using rand(): of the two arrays; S [5] and A [5] and use loops to calculate the sum and average and A each column of the two dimensional array, assign the results to S and A, respectively (i.e. calculate the sum and average of the numbers from n[0][0] to n[4][0] and assign it to S[0] and A[0], calculate the sum of the numbers from n[1][0] to n[4][1] and assign it to S[1] and A[1], etc.) Output the results in S array and A array; finally, count how many even numbers of the two-dimensional array has and output the result. The following specifications will be expected for each of your projects in this class: An empty project file must be created first, and then you will create new source file and header files. Add comments at the beginning of the program, and add description for each function, loop. etc. Turn in both the hardcopy and softcopy of your source code, including all .cpp and .h files. Your name, your ID number and HW number should be written on the upper-right corner of the first sheet of the hardcopy. Note that you are required to submit your softcopy to assignment 1 (b1, b2) in Task stream. Date Due: Wednesday, February 22th. 2017

Explanation / Answer

// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <stdlib.h> /* srand, rand */
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <vector>


using namespace std;

int main()
{
srand (time(NULL));
  
int n[5][5];
int countEven = 0;

cout << "Random 2-D array: ";
// assign random number in range 10-100
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
{
n[i][j] = rand()%90 + 10;
// count even numbers
if(n[i][j]%2 == 0)
countEven++;

cout << n[i][j] << " ";
}
cout << endl;
}

double S[5] = {0};
double A[5];

// iterating over the column
for (int i = 0; i < 5; ++i)
{
// iterating over rows
for (int j = 0; j < 5; ++j)
{
S[i] = S[i] + n[j][i];
}

A[i] = S[i]/5;
}

cout << endl << endl;
for (int i = 0; i < 5; ++i)
{
cout << "Sum of column " << (i+1) << ": " << S[i] << endl;
cout << "Average of column " << (i+1) << ": " << A[i] << endl;
}

cout << " There are " << countEven << " even numbers ";
return 0;
}

/*
output:

Random 2-D array:
66 28 18 74 19
38 17 74 73 78
72 33 63 23 98
45 53 74 27 88
72 95 82 58 52


Sum of column 1: 293
Average of column 1: 58.6
Sum of column 2: 226
Average of column 2: 45.2
Sum of column 3: 311
Average of column 3: 62.2
Sum of column 4: 255
Average of column 4: 51
Sum of column 5: 335
Average of column 5: 67

There are 15 even numbers


*/

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