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

You are to write a program that will perform calculations with a two dimensional

ID: 3537941 • Letter: Y

Question

You are to write a program that will perform calculations with a two dimensional array.

You are to development the following functions to support this effort. Write a function for each of the following actions.

Read function in values into a 2-D array: File TwoDim.txt

GetTotal function accepts 2D array and returns total of all values

getAverage func accepts 2D array and returns average of all values

getRowTotal func accepts 2d array, an integer (row) returns total for that row.

getColTotal func accepts 2d array, an integer (column) returns total for that column.

GetHighestInRow func accepts 2d array row nbr returns highest number in row.

GetHighestInCol func accepts 2d array col nbr returns highest number in col.

GetLowestInRow func accepts 2d array row nbr returns lowest number in row.

GetLowestInCol func accepts 2d array col nbr returns lowest number in col.

Print out the array, one row per line. (yes for my test, a row will fit on one line.)

Write a function that will find 4 adjacent numbers (horizontal, vertical, or diagonal) in the array


Input:   I will supply you a pseudo main program that will be used to test your functions. I will not be able to give you the actual code, because I will not know the name of your routines or the order of your arguments. You will write the main program to test your code.


Pseudo Code Main:


Label all output

Read in data. 15 x 15 array.

Print array

Compute and print total array avg

Compute and print individual totals for row 5 thru 10

Compute and print individual totals for col 2 thru 8

Find the biggest numbers in each odd number rows.

Find the smallest number in each even number cols.

Add all values togather for cols 7 thru 12 (one number answer)

Add together the biggest numbers form each column 9 thru 14 (one number)

Add together the smallest numbers from each row 0 thru 6 (one number)

Find the four adjacent numbers that sum to the largest sum in the array.


You are to write a program that will perform calculations with a two dimensional array.


Input: I have the text file but can't attach it here it consists of 225 numbers in a single coloumn and would take up too much space. Can this be written without text code and just a sample used until completed and I insert the correct text file.




Explanation / Answer

#include <iostream>

#include <fstream>

using namespace std;

void read(int a[15][15])

{

int i,j;

ifstream file("cheggtext.txt");

for(i=0;i<15;i++){

for(j=0;j<15;j++){

file>>a[i][j];

}

}

return;

}

int gettotal(int a[15][15])

{

int s=0,i,j;

for(i=0;i<15;i++){

for(j=0;j<15;j++){

s+=a[i][j];

}

}

return s;

}

int getaverage(int a[15][15])

{

int s = gettotal(a);

return s/225;

}

int getrowtotal(int a[15][15],int b)

{

int i,s=0;

for(i=0;i<15;i++){

s+=a[b][i];

}

return s;

}

int getcoltotal(int a[15][15],int b)

{

int i,s=0;

for(i=0;i<15;i++){

s+=a[i][b];

}

return s;

}

int gethighestinrow(int a[15][15],int b)

{

int p,i;

p=a[b][0];

for(i=1;i<15;i++){

if(a[b][i]>p) p=a[b][i];

}

return p;

}

int gethighestincol(int a[15][15],int b)

{

int p,i;

p=a[0][b];

for(i=1;i<15;i++){

if(a[i][b]>p) p=a[i][b];

}

return p;

}

int getlowestinrow(int a[15][15],int b)

{

int p,i;

p=a[b][0];

for(i=1;i<15;i++){

if(a[b][i]<p) p=a[b][i];

}

return p;

}

int getlowestincol(int a[15][15],int b)

{

int p,i;

p=a[0][b];

for(i=1;i<15;i++){

if(a[i][b]<p) p=a[i][b];

}

return p;

}

void printarray(int a[15][15])

{

int i,j;

for(i=0;i<15;i++){

for(j=0;j<15;j++){

cout<<a[i][j]<<" ";

}

cout<<endl;

}

return;

}

void highestsum(int a[15][15])

{

int i,j,s;

s=a[0][0]+a[0][1]+a[0][2]+a[0][3];

for(i=0;i<15;i++){

for(j=0;j<15;j++){

if(i<12 && j<12){

if(s<a[i][j]+a[i][j+1]+a[i][j+2]+a[i][j+3]) s=a[i][j]+a[i][j+1]+a[i][j+2]+a[i][j+3];

if(s<a[i][j]+a[i+1][j]+a[i+2][j]+a[i+3][j]) s=a[i][j]+a[i+1][j]+a[i+2][j]+a[i+3][j];

if(s<a[i][j]+a[i+1][j+1]+a[i+2][j+2]+a[i+3][j+3]) s=a[i][j]+a[i+1][j+1]+a[i+2][j+2]+a[i+3][j+3];

}

}

}

for(i=0;i<15;i++){

for(j=0;j<15;j++){

if(i<12 && j<12){

if(s==a[i][j]+a[i][j+1]+a[i][j+2]+a[i][j+3]) cout<<a[i][j]<<" "<<a[i][j+1]<<" "<<a[i][j+2]<<" "<<a[i][j+3]<<" "<<endl;

if(s==a[i][j]+a[i+1][j]+a[i+2][j]+a[i+3][j]) cout<<a[i][j]<<" "<<a[i+1][j]<<" "<<a[i+2][j]<<" "<<a[i+3][j]<<" "<<endl;

if(s==a[i][j]+a[i+1][j+1]+a[i+2][j+2]+a[i+3][j+3]) cout<<a[i][j]<<" "<<a[i+1][j+1]<<" "<<a[i+2][j+2]<<" "<<a[i+3][j+3]<<" "<<endl;

}

}

}

return;

}

int main()

{

int a[15][15],i,s=0;

read(a);

printarray(a);

for(i=5;i<=10;i++){

cout<<"sum of "<<i<<" row: "<<getrowtotal(a,i)<<endl;

}

for(i=2;i<=8;i++){

cout<<"sum of "<<i<<" col: "<<getcoltotal(a,i)<<endl;

}

for(i=1;i<15;i+=2){

cout<<"biggest of "<<i<<" row "<<gethighestinrow(a,i)<<endl;

}

for(i=0;i<15;i+=2){

cout<<"biggest of "<<i<<" col "<<gethighestincol(a,i)<<endl;

}

for(i=7;i<=12;i++){

s+=getcoltotal(a,i);

}

cout<<"col total 7 to 12 : "<<s<<endl;

s=0;

for(i=9;i<=14;i++){

s+=gethighestincol(a,i);

}

cout<<"col highest sum 9 to 14 : "<<s<<endl;

s=0;

for(i=0;i<=6;i++){

s+=getlowestinrow(a,i);

}

cout<<"row lowest sum 0 to 6 : "<<s<<endl;

cout<<"number that add to highest sum: "<<endl;

highestsum(a);

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