smartperraorwhateva
28.11.2019 •
Computers and Technology
(statistics) write a program that includes two functions named calcavg() and the calcavg() function should calculate and return the average of values stored in an array named testvals. the array should be declared in main() and include the values 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, and 73. the variance() function should calculate and return the variance of the data. the variance is obtained by subtracting the average from each value in testvals, squaring the values obtained, adding them, and dividing by the number of elements in testvals. the values returned from calcavg() and variance() should be displayed by using cout statements in
Solved
Show answers
More tips
- C Computers and Internet How to Delete Your Account on Odnoklassniki...
- H Health and Medicine What to Do When Your Jaw Locks Up?...
- G Goods and services What Are the Most Popular Services?...
- P Philosophy How did the concept of module arise in computer science?...
- F Food and Cooking How to Cook Julienne? Recipes and Tips...
- D Dating, Love, Relationships 10 Useful Tips on How to Survive a Breakup?...
- F Food and Cooking Apple Cider Vinegar: The Ultimate Health and Beauty Solution...
- C Computers and Internet Е-head: How it Simplifies Life for Users?...
- F Family and Home How to Choose the Best Diapers for Your Baby?...
Answers on questions: Computers and Technology
- C Computers and Technology Permute rows within bands If you permute the rows within the same band of a valid Sudoku board, you will obtain another valid board: 1 2 3 4 5 67 8 9 7 8 9 2 3 4 5 6...
- C Computers and Technology What are the ethical implications of online social media after someone has died? what ethical concerns might exist?...
- C Computers and Technology A flower is an example of ? (Select the best answer.) Question 2 options: Water Soil Fauna Flora Air...
- C Computers and Technology Universal Containers wants to set up SSO for a selected group of users to access external applications from salesforce through App launcher. Which three steps must be...
- M Mathematics Update from me failing online school: I just found out that I somehow passed :D...
- M Mathematics Which part of the angle is the vertex?...
- S Social Studies most of the statues in Nepal are related to different religions and tradition.they are more influenced by religion than art give reasons...
- L Law HELP PLEASE (Forensic Science on FLVS) What are two things that can damage DNA after replication?...
- M Mathematics John can run a mile in 8 minutes. If he ran for an hour and 4 minutes how many miles did he run?...
- B Biology Id 405 147 7041 pass 87654321 for fun...
Ответ:
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;
}
Output:
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 arraywe 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.
Ответ: