ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 9 Weeks Ago, 5 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 26 Apr 2017 My Price 11.00

calculating the mean, median, and the rest of the functions

How can i create a sort function to sort the entered integers from lowest to biggest before calculating the mean, median, and the rest of the functions. sort function is what i need . email attachment on what I need to do for the sortingIMG_0657.PNG

 

 

#include <iostream>

#include <stdlib.h>

#define SIZE 10

using namespace std;

// SIGNATURES of all the required Functions

void display(int []);

double mean(int []);

int median(int []);

void lessThanFive(int []);

int minimum(int []);

int sum(int []);

// MAIN FUNCTION

int main()

{

int arr[SIZE]; // Array to store the integers

double avrg; // To store the average returned by the mean() Function

int mid = 0; // To store the median returned by the median() Function

int mini; // To store the minimum value of the array returned by the minimum() Function

int total =0;

// Read the values for the array

cout << "nEnter 10 values in the array (one by one):" << endl;

for(int i =0; i < SIZE; i++){

cin >> arr[i];

}

// Function call to display()

display(arr);

// Function call to mean()

avrg = mean(arr);

cout << "nAverage of the 10 values of the array is: " <<avrg;

// Function call to median()

mid = median(arr);

cout << "nMiddle Value of the array is: " << mid;

//Function call to lessThanFive()

lessThanFive(arr);

// Function call to minimum()

mini = minimum(arr);

cout << "nMinimum value in the array is: " << mini << endl;

// Function call to sum()

total = sum(arr);

cout << "nSum of the 10 digits in the array: " << total;

cout << endl;

return 0;

}

 

// Function display(): To display all the integers in the array

void display(int arr[]){

cout << "nIntegers in the array: " << endl;

// Loop through every index of the array and print it on the screen

for(int i =0; i < SIZE; i++){

cout << arr[i] << " " ;

}

cout << endl;

}

// Function mean(): To return the average of the 10 values in the array

double mean(int arr[]){

int sum = 0;

double average = 0.0; // To store the average of Integers

// Loop through all the values and add them together

for(int i =0; i < SIZE; i++){

sum = sum + arr[i];

}

average = (double)sum / SIZE ;

return (average); // Returning the Average of the values

}

// Function median(): To return the middle value of the array

int median(int arr[]){

int average = 0;

int middle1, middle2; // To store the middle positions

middle1 = SIZE / 2;

middle2 = (SIZE / 2) - 1;

if((SIZE % 2) == 0) // If the size of the array is even

{

average = (arr[middle1]+arr[middle2]) / 2;

cout<<"nnThe no. of values is even! Getting Average of the two middle values...";

return average;

}

else{

return arr[middle1];

}

}

// Function lessThanFive(): To display values in the array which are less than 5

void lessThanFive(int arr[]){

int count = 0;

cout<<"nnThese are the values in the array which are less than 5: " << endl;

// Loop through all the values and check if they are less than five

for(int i =0; i < SIZE; i++){

if (arr[i] < 5){

cout << arr[i] << " ";

count ++;

}

}

if(count == 0)

cout << "There is no such value!" << endl;

cout << endl;

}

// Function minimum(): To return the minimum value in the array

int minimum(int arr[]){

int minval = arr[0]; // set the default minimum value to the first value

// Loop through all the values and check if they are less than the current minimum value

for(int i =0; i < SIZE; i++){

if(arr[i] < minval) // If the value is less, set minval = value in the array

minval = arr[i];

}

return minval; // Returning the minimum value

}

// Function sum(): To return the sum of the 10 digits in the array

int sum(int arr[]){

int totalval = 0; // Set default sum equal to 0;

// Loop through each value in the array and add it to the previous sum

for(int i =0; i < SIZE; i++){

totalval = totalval + arr[i];

}

return totalval; // Return the sum

}

Attachments:

Answers

(11)
Status NEW Posted 26 Apr 2017 03:04 AM My Price 11.00

-----------

Attachments

file 1493176890-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)