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

19.1s points) Finish writing the definition for the function Arraystats which ta

ID: 3731034 • Letter: 1

Question

19.1s points) Finish writing the definition for the function Arraystats which takes in 2 parameters: e a const 2-dimensional array of doubles where there are coLs (a defined constant) number of elements in each row an wsigned int representing the number of rows. and retu rms a value of type statistics (a struct as defined below) The function should mean of all the elements of the array This finc This fiunction d return the struct containing the low value, the high value, the sum and the the s rion performs no input or output to the console! should work on any 2D array of doubles where there are 2 columns in each row! By way of example, if the function were called by the following code: #de fine COLS 2u #define ROWS 3u double da [ROWS] [COLS] (2.1, 3.2 1.2, 2.4), 0.6, 5.S) struct stats double lowValue double highValue double sum; double mean; typedef struct stats statistics; 11.. statistics mystats- ArrayStats (da, ROWS) for myStats, low Value would be set to 0.6, highValue would be set to 5.5, Sum would et to 15.0 and mean would be set to 2.5 (the sum divided by the total mumber of elements) tatistics ArrayStats(

Explanation / Answer

#include <iostream>
using namespace std;

#define COLS 2
#define ROWS 3

double da[ROWS][COLS] = { {2.1,3.2},{1.2,2.4},{0.6,5.5}};

struct stats
{
double lowValue;
double highValue;
double sum;
double mean;

};

typedef struct stats statistics;

statistics ArrayStats(double da[][COLS],int r)// functional definition
{
int i,j;
double high=0;
double low = 9999;
double sum = 0;

statistics myStats;
for(i=0;i<r;i++)
{
  for(j=0;j<COLS;j++)
  {
  if(da[i][j] >high) // if any number in array da is higher than high
  high = da[i][j]; // set that number to high
  if(da[i][j] <low) // if any number in array da is lower than low
  low = da[i][j]; // set that number to low
  sum = sum + da[i][j]; // compute sum of elements of da
  }
}
myStats.lowValue = low;
myStats.highValue = high;
myStats.sum = sum;
myStats.mean = sum/(ROWS*COLS);
return myStats;
}
int main() {

statistics myStats = ArrayStats(da,ROWS);

cout<<" myStats.lowValue : "<<myStats.lowValue;
cout<<" myStats.highValue : "<<myStats.highValue;
cout<<" myStats.sum : "<<myStats.sum;
cout<<" myStats.mean : "<<myStats.mean;
return 0;
}

Output:

myStats.lowValue : 0.6
myStats.highValue : 5.5
myStats.sum : 15
myStats.mean : 2.5

Do ask if any query. Please upvote if the anser is helpful

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