Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Goal :This assignment is to get familiar with the following : C++ integer array,

ID: 3784219 • Letter: G

Question

Goal :This assignment is to get familiar with the following :

C++ integer array, dynamic array

C++ functions , parameters passing, overloading

C++ string

selection sort using C++

C++ format output using printf()

You have to design and implement a C++ console application that : prompts the user to enter a positive integer N , and

generate N random numbers between 0 and 100 (inclusively) and store them in a dynamic integer array.

display the following statistics of the data being generated:

the largest number

the smallest number

the average of the data set. The average must have exactly two digits after the decimal place.

the variance of the data set.

the standard deviation of the data set.

display the data set in the sorted order. (in ascending order)

display the data set in form of histogram.(see the sample output here)

Requirements

In order to achieve the above , you must implement the following functions :

Explanation / Answer

I am uploading code for first four functions:

#include<iostream>
using namespace std;

//function prototype
int sum(int a[], int n) ; // return the sum of all elements from the integer array a of size n
int sumOfSquare(int a[], int n) ; // return the sum of the square of each element from integer array a of size n
int max(int a[] , int n); // return the largest element of the array a of size n
int min(int a[], int n) ; // return the smallest element of the array a of size n

int main()
{
int n;
cout<<"Please enter the value of n: ";
cin>>n;
int a[n];
cout<<"Please enter the array values: ";
for(int i=0;i<n;i++)
cin>>a[i];

cout<<"Sum of all elements from the integer array is: "<<sum(a,n)<<endl;
cout<<"Sum of the square of each element from integer array is: "<<sumOfSquare(a,n)<<endl;
cout<<"Largest element of array is: "<<max(a,n)<<endl;
cout<<"Smallest element of array is: "<<min(a,n);

return 0;
}//end of main function

int sum(int a[],int n)
{
int sum =0 ;
for(int i=0;i<n;i++)
sum = sum + a[i];
return sum;
}

int sumOfSquare(int a[], int n)
{
int sum =0 ;
for(int i=0;i<n;i++)
sum = sum + a[i]*a[i];
return sum;
}
int max(int a[],int n)
{
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i]>max)
max = a[i];
}
return max;
}

int min(int a[],int n)
{
int min = a[0];
for(int i=1;i<n;i++)
{
if(a[i]<min)
min = a[i];
}
return min;
}

Output:

Please enter the value of n: Please enter the array values:
Sum of all elements from the integer array is: 15
Sum of the square of each element from integer array is: 55
Largest element of array is: 5
Smallest element of array is: 1

Please visit this url in case of any query with given code:

http://ideone.com/vnIKCK

Hope it helps.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote