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]
2 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]2 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
A string that contains only 0s,1s, and 2s is called a ternary string. How many strings of 10 ternary digits (0, 1, or 2) are the
alexdok [17]

Answer:

Number of strings = (10, 2)×(8,3) = 2520

Explanation:

The number of possible combinations for taking two 0's is C(10, 2)

It remains 8 Positions

The number of possible combinations for taking three 1's is C(8,3)

So there remains 5 spots

8 0
3 years ago
Read 2 more answers
Which of the following software is cloud-based? OpenOffice Writer Word 2013 Word Online Word Perfect\
evablogger [386]
I think its open office
3 0
3 years ago
Read 2 more answers
The PadRight function has two parameters: S (a string) and N (an int), and returns as its result the string S padded on the righ
oee [108]

Answer:

The following code is written in python programming language:

def PadRight(S,N):   #define user defined function

 if(len(S)<N):    # set if condition

   S=S.ljust(N)   #set the space to right

   return S       # return the result

 

def PadLeft(S,N):    #define user defined function

 if(len(S)<N):    # set if condition

   S=S.rjust(N)   # set the space to left

   return S       # return the result

'''calling the function'''

print(PadLeft("Frog",7))

print(PadRight("Frog",7))

Output:

      Frog

Frog

Explanation:

Here, we define a user defined function "PadRight()" and pass two arguments in its parameter "S", "N".

Then, set the if condition and pass condition "len(S)<N" then, if the condition is true then the code inside the if condition set the space to right then, return the output.

After that, we again define a user defined function "PadLeft()" and pass two arguments in its parameter "S", "N".

Then, set the if condition and pass condition "len(S)<N" then, if the condition is true then the code inside the if condition set the space to right then, return the output.

6 0
3 years ago
Software refers to:
aev [14]

Answer:

Software refers to the programs that run on your computer.

Explanation:

Examples are Word and PowerPoint. Computer programs contain instructions that the hardware carries out. ... Another program (called a compiler or interpreter) translates these instructions into machine language which the computer hardware understands.

7 0
2 years ago
Read 2 more answers
1. To collect data from two websites with different URLs using a single Google Analytics property, what feature must be set up?
Finger [1]

Answer:Cross domain tracking

Explanation: Cross domain tracking is the tracking activity of the several domains in the Google Analytics property's single unit. This tool works for tracking by the means of debugging and finding solution of the problem.

Cross tracking is also seen as the complex task and the solution is not east to obtain.This tools comes into action when domain session need the tracking of two or more domains or sub-domains.

6 0
3 years ago
Other questions:
  • What type of topology gives you a direct connection between two routers so that there is one communication path?
    14·1 answer
  • What is computer hacking? describe some examples
    6·1 answer
  • While researching ideas for cutting energy costs is his company. Hector watches an online video in which a business expert says,
    6·2 answers
  • Use induction on n to prove that fir all n&gt;=2, 2^n+3^n&lt;5^n
    11·1 answer
  • A cell reference with only one dollar sign before either the column or the row is called an absolute reference.
    10·1 answer
  • Describe the differences between program development and program execution, including the installed software required for develo
    5·1 answer
  • Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by ea
    12·1 answer
  • Please please help I don’t understand
    6·1 answer
  • There are a wide variety of nonsampling errors that can occur during data collection including the first type, ________.
    7·1 answer
  • What are tasks performed by pascaline?​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!