****This is all one problem. Please read carefully. I need help with pc18 on pg
ID: 3621045 • Letter: #
Question
****This is all one problem. Please read carefully.I need help with pc18 on pg 464, but the information in pc13 on pg 460 need to be used to create the coding for pc 18.*****
****I have included all information here
*****pc 18 directions pc 13 info is on the bottom ( please read carefully)
2D Array Operations
Write a program that creates a two-dimensional array
The program should have the following functions:
• getTotal. This function should accept a two-dimensional array as its argument
and return the total of all the values in the array.
• getAverage. This function should accept a two-dimensional array as its argument
and return the average of all the values in the array.
• getRowTotal. This function should accept a two-dimensional array as its first
argument and an integer as its second argument. The second argument should be
the subscript of a row in the array. The function should return the total of the values
in the specified row.
• getColurnnTotal. This function should accept a two-dimensional array as its first
argument and an integer as its second argument. The second argument should be
the subscript of a column in the array. The function should return the total of the
values in the specified column.
• getHighestlnRow. This function should accept a two-dimensional array as its
first argument and an integer as its second argument. The second argument
should be the subscript of a row in the array. The function should return the highest
value in the specified row of the array.
• getLowestlnRow. This function should accept a two-dimensional array as its first
argument and an integer as its second argument. The second argument should be
the subscript of a row in the array. The function should return the lowest value in
the specified row of the array.
Demonstrate each of the functions in this program
*****Use this data for the program
*** Data must be included in program
Test Score Letter Grade (pc 13 info)
90-100 A
80-89 B
70-79 c
60-69 D
0-59 F
Explanation / Answer
please rate - thanks
better?
# include <iostream>
#define NROW 4
#define NCOL 5
using namespace std;
int getTotal(int[][NCOL]);
int getRowTotal(int[][NCOL],int);
int getColumnTotal(int[][NCOL],int);
double getAverage(int);
int getLowestInRow(int[][NCOL],int);
int getHighestestInRow(int[][NCOL],int);
char getgrade(int);
int main ()
{int i,j,choice,val;
double avg;
char letter;
int num[NROW][NCOL]={75,65,90,80,45,66,88,90,99,100,59,87,78,98,32,99,77,88,55,66};
cout<<"The Matrix ";
for(i=0;i<NROW;i++)
{for(j=0;j<NCOL;j++)
cout<<num[i][j]<<" ";
cout<<endl;
}
for(;;)
{cout<<"Choose what you would like to do ";
cout<<"1 get Total of all values in matrix: ";
cout<<"2 get Average of all values in matrix: ";
cout<<"3 get a Row Total ";
cout<<"4 get a Column Total ";
cout<<"5 get the Highest value In a Row ";
cout<<"6 get the Lowest value In a Row ";
cout<<"7 Exit ";
scanf("%d",&choice);
switch(choice)
{case 1: cout<<"Total= "<<getTotal(num)<<endl;
break;
case 2: val=getTotal(num);
avg=getAverage(val);
letter=getgrade((int)avg);
cout<<"The average is "<<avg<<endl;
cout<<"Which is a "<<letter<<endl;
break;
case 3: cout<<"Enter row : ";
cin>>i;
if(i<0||i>=NROW)
{cout<<"Error-must be between 0 and "<<NROW<<" ";
break;
}
else
cout<<"Row "<<i<<" total is "<<getRowTotal(num,i)<<endl;
break;
case 4: cout<<"Enter column: ";
cin>>i;
if(i<0||i>=NCOL)
{cout<<"Error-must be between 0 and "<<NCOL<<" ";
break;
}
else
cout<<"Column "<<i<<" total is "<<getColumnTotal(num,i)<<endl;
break;
case 5: cout<<"Enter row : ";
cin>>i;
if(i<0||i>=NROW)
{cout<<"Error-must be between 0 and "<<NROW<<" ";
break;
}
else
{val=getHighestestInRow(num,i);
cout<<"Highest element in row "<<i<<" is "<<val<<endl;
letter=getgrade(val);
cout<<"Which is a "<<letter<<endl;
}
break;
case 6: cout<<"Enter which row : ";
cin>>i;
if(i<0||i>=NROW)
{cout<<"Error-must be between 0 and "<<NROW<<" ";
break;
}
else
{val=getLowestInRow(num,i);
cout<<"Lowest element in row "<<i<<" is "<<val<<endl;
letter=getgrade(val);
cout<<"Which is a "<<letter<<endl;
}
break;
case 7: system("pause");
return 0;
default: cout<<"Error!! Try Again ";
}
}
}
char getgrade(int n)
{if(n>=90)
return 'A';
else if(n>=80)
return 'B';
else if(n>=70)
return 'C';
else if(n>=60)
return 'D';
else
return 'F';
}
int getTotal(int r[][NCOL])
{int i,j;
int val=0;
for(i=0;i<NROW;i++)
for(j=0;j<NCOL;j++)
val+=r[i][j];
return val;
}
int getHighestestInRow(int num[][NCOL],int n)
{int i;
int val=0;
val=num[n][0];
for(i=1;i<NCOL;i++)
if(num[n][i]>val)
val=num[n][i];
return val;
}
double getAverage(int t)
{return (double)t/(NROW*NCOL);
}
int getLowestInRow(int num[][NCOL],int n)
{int i;
int val=0;
val=num[n][0];
for(i=1;i<NCOL;i++)
if(num[n][i]<val)
val=num[n][i];
return val;
}
int getRowTotal(int num[][NCOL],int n)
{int i;
int val=0;
for(i=0;i<NCOL;i++)
val+=num[n][i];
return val;
}
int getColumnTotal(int num[][NCOL],int n)
{int i;
int val=0;
for(i=0;i<NROW;i++)
val+=num[i][n];
return val;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.