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

2D Arrays - C++ Label all outputs 1. Read in data for a 15 x 15 2d array (data f

ID: 3665300 • Letter: 2

Question

2D Arrays - C++
Label all outputs

1. Read in data for a 15 x 15 2d array (data found here: http://pastebin.com/QtJCGZCg)
2. Print Array
3. Compute and print average for all values in the 2-d array
4. Compute and print totals for each row for rows 5 through 10
5. Compute and print totals for each column for columns 2 through 8
6. Find the biggest numbers in each odd numbered rows.
7. Find the smallest number in each even numbered columns.
8. Sum all the values for columns 7 through 12 (one number answer)
9. Sum all the values for rows 10 through 14 (one number answer)
10. Sum together the biggest numbers from each column 2 through 8 (one number)
11. Sum together the smallest numbers from each row 0 through 6 (one number)
12. Find the four adjacent numbers that sum to the largest sum in the array. (Four adjacent numbes can be in a row, column, or one of the diagonals (8 possible directions)

Restrictions: Can only use these functions -
1. A readIn function to read the values into the 2-d array (fill columns, then rows)
2. A RowTotal function that accepts the 2d array, an integer (row) and returns the total for that row.
3. A ColTotal function that accepts the 2d array, an integer (column) and returns the total for that column.
4. A HighestInRow function that accepts the 2d array, row nbr returns the highest number in the row.
5. A HighestInCol function that accepts the 2d array, col nbr returns highest number in column.
6. A LowestInRow function that accepts the 2d array, row nbr returns the lowest number in the row.
7. A LowestInCol function that accepts the 2d array, col nbr returns lowest number in column.
8. A Print function that reads the array one row per line.
9. Write a function (or functions) that will find the 4 adjacent numbers (horizontal, vertical, or diagonal) in the array that sums to the largest value. The four numberes have to be adjacent values in one of 8 directions.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void readln(int a[][])
{
for(int i;i<15;i++)
{
for(int j; j<15; j++)
{
cout<<a[i][j];
}
}
}
int rowTotal(int n)
{
int sum = 0;
if(n >= 5 && n<=10)
{
for(int j = 0; j<15;j++)
{
sum = sum+a[n][j];
}
}
}
int colTotal(int n)
{
int sum = 0;
if(n >= 2 && n<=8)
{
for(int i = 0; i<15;i++)
{
sum = sum+a[i][n];
}
}   
return sum;   
}
int main()
{
int a[15][15], i, j,total=0,n;
float avg;
for(i=0;i<15;i++)
{
for(j=0;j<15;j++)
{
cin>>a[i][j];
}
}
readln(a)
for(i =0;i<15;i++)
{
for(j=0;j<15;j++)
{
total = total +a[i][j];
}
}
avg = (float)total/(float)225;
cout<<"Average of all values in the 2-d array is"<<avg;
cout<<"Enter the row for which you have to find total";
cin>>n;
rowTotal(n);
cout<<"Enter the column for which you have to find total";
colTotal(n);
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