1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erma4kov [3.2K]
3 years ago
10

(Statistics) Write a program that includes two functions named calcavg() and variance(). 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 main().
Computers and Technology
1 answer:
Gwar [14]3 years ago
7 0

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.

You might be interested in
Computer-aided design software is used primarily by:
guapka [62]
Is used primarily by Students and Engineers.
4 0
4 years ago
HELP ME PLEASE <br> Can you help get back my ro blox account: (LOLCrashForce)
abruzzese [7]

Answer: sorry we cannot help

Explanation:

5 0
3 years ago
Read 2 more answers
The which command _________________. a. can only be used to search for executables b. searches for a file in all directories sta
dsp73
Answer: D. Searches for a file only in the directories that are in the path variable
6 0
2 years ago
Evaluating how current, credible, and unbiased a source is ensures:
Tanya [424]

The answer is

A. your information is more accurate and useful

I hope it helps you. Please mark me brainliest answer.

6 0
3 years ago
Question 5 of 5
Archy [21]

<u>Answer:</u>

<em>Sewage treatment Programs </em>

<u>Explanation:</u>

Sewage treatment programs are the right choice <em>because these are the source to create germs and if we understand how to be clean, most of the disease is avoided. </em>

<em>Drug regulation:</em> It is nothing but the continuous treatment of prolonged disease where pills needs to be taken regularly to protect patients from death or to avoid disease become more severe.

<em>Physical fitness campaign:</em> This concentrate on to how to keep bod fit through exercise and it does not deal with hygiene.

<em>Nutrition Education:</em> It’s a kind of protection mechanism where in-take of food is really concentrated to fight against germs.

5 0
4 years ago
Other questions:
  • Using the slice operator, print your first, then last name.2. Print the length of your first name.3. Assume you have two variabl
    6·1 answer
  • HELP ME WITH JAVA: This is my assignment. I need to write a program with a main method and methods. Use a scanner to get the Str
    5·1 answer
  • As the demand for goods and services decreases, job growth.
    14·2 answers
  • You are the owner of a computer component manufacturing company. Your manufacturing plant has 10 different machines that can be
    6·1 answer
  • What is a preemptive CPU scheduling algorithm? Give an example and explain.
    7·1 answer
  • Generally speaking, problems are rarely caused by motherboards. However, there are some instances in which a motherboard can fai
    12·1 answer
  • I need to create a method named "root positive". which will either print the square root of the number passed to it or if the nu
    13·1 answer
  • What could have made you redesign your plan? Select 3 options.
    6·1 answer
  • def list_length(shrinking_list): ''' A recursive way to count the number of items in a list. ''' if shrinking_list
    10·1 answer
  • You have been trying all day to check your direct messages on social media. The site is really slow to load and sometimes you ca
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!