Below is the C++ code I hope that i have provided sufficient comments for your better understanding
#include<bits/stdc++.h>
using namespace std;
//declaration
int minimum(int* A);
int maximum(int* A);
double mean(int* A);
double deviation(int* A,double mean);
//global variable
int n;
int main()
{
int choice,p;
double q;
//Take user's input
cout<<"Please enter N : ";
cin>>n;
int a[n];
cout<<"Enter "<<n<<" integers :
"<<endl;
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"Enter an option\n";
cout<<"1. Find minimumimum"<<endl;
cout<<"2. Find maximumimum"<<endl;
cout<<"3. Find mean"<<endl;
cout<<"4. Find standard deviation"<<endl;
cin>>choice;
switch(choice)
{
case 1:
p=minimum(a);
cout<<"Minimum value is "<<p;
break;
case 2:
p=maximum(a);
cout<<"Maximum value is "<<p;
break;
case 3:
q=mean(a);
cout<<"Mean value is "<<q;
break;
case 4:
q=deviation(a,mean(a));
cout<<"Standard deviation value is "<<q;
break;
}
return 0;
}
int minimum(int* a)
{
//initialize result as 1st value of array
int res=a[0];
for(int i=1;i<n;i++)
{
//update result if necessary
if(a[i]<res)
res=a[i];
}
return res;
}
int maximum(int* a)
{
//initialize result as 1st value of array
int res=a[0];
for(int i=1;i<n;i++)
{
//update result if necessary
if(a[i]>res)
res=a[i];
}
return res;
}
double mean(int* a)
{
double sum=0.0,res;
//calculate sum of all values
for(int i=0; i<n; ++i)
{
sum += a[i];
}
//calculate average
res = sum/n;
return res;
}
double deviation(int* A,double mean)
{
double standardDeviation = 0.0;
//calculate standard deviation
for(int i=0; i<n; ++i)
standardDeviation += pow(A[i] - mean, 2);
return sqrt(standardDeviation/n);
}
Below is the screenshot of output
Hope i have answered your question satisfactorily.Leave doubts in
comment section if any.
that can calculate several statistical measures of data. Write a program collects N integers from the...
Write a C++ program that repeatedly collects positive integers from the user, stopping when the user enters a negative number or zero. After that, output the largest positive number entered. A sample run should appear on the screen like the text below. Enter a number: 3 Enter a number: 10 Enter a number: 2 Enter a number: -213 Output: The largest positive number you entered was 10.
1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in); } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...
14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a set numbers (assume that the numbers in the set is less than 20) using overload methods. The program first prompts the user to enter a character; if the character is 'I' or 'i', then invokes the appropriate methods to process integer data set; if the character is 'R' or 'r', then invokes the appropriate methods to process real number data set; if the inputted...
Program already solved, but I need to put function documentation headers for each and every function in your program (for the ones you write, and keep the function header I give you for the main() function). Also make sure you keep the file block header at the top of the file, and fill in the information correctly. Secondly this week you must get your indentation correct. All indentation must use 2 spaces, and you should not have embedded tabs in...
Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should perform the following steps: A) Ask the user how many students were surveyed. An array of integers with this many elements should then be dynamically allocated. B) Allow the user to enter the number of movies each student saw into the array. C) Calculate and display the average, median, and mode of the values entered....
Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...
2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...
Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...
Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...
You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...