Answer:
Following are the program in the C++ Programming Language.
#include<iostream> //set header file
using namespace std; //namespace
//set method for sum and average
double calcavg(int a[])
{
double t=0;
double average ;
cout<<"Arraylist is : "<<endl;
for(int i=0;i<14;i++) //set for loop
{ cout<<a[i]<<" ";
t = t+a[i];
}
cout<<endl<<endl;
average = t/14;
cout<<"total : "<<t<<endl; //print message with output
return average; //return the average
}
//set method for the variance
double variance(int a[],double average)
{
double t=0;
for(int i=0;i<14;i++) //set the for loop
{
a[i] = (a[i]-average) * (a[i]-average);
t = t+a[i];
}
double variance = t/14;
return variance; // return variance
}
int main() //define main method
{
double average;
double variances ;
//set array data type declaration
int testvals[]={89,95,72,83,99,54,86,75,92,73,79,75,82,73};
average = calcavg(testvals); //call the methods
variances = variance(testvals,average); //call the methods
cout<<"average is : "<<average<<endl; //print output
cout<<"variance is : "<<variances<<endl;//print output
return 0;
}
<u>Output</u>:
Arraylist is :
89 95 72 83 99 54 86 75 92 73 79 75 82 73
total : 1127
average is : 80.5
variance is : 124.429
Explanation:
Here, we set the function "calcavg()" in which we pass integer data type array argument "a[]" in its parameter.
- inside it, we set two double type variable "t" and assign its value to 0 and "average"
- we set the variable "t" to find the total sum of the array
- we set the variable "average" to find the average of the array.
Then, we set the function "variance()" in which we pass two argument, integer array type argument "a[]" and double type argument "average" in its parameter.
- inside it, we find the variance of the array.
Finally, we define the "main()" function in which we call both the functions and pass values in its argument and then print the output.