What is mode and how do you calculate it ? In Statistics, the mode of a set of v
ID: 3538266 • Letter: W
Question
What is mode and how do you calculate it? In Statistics, the mode of a set of values is a value that occurs most often. Write a function called findMode that accepts as arguments the following:
a. An array of integers.
b. An integer that indicates the number of elements in the array.
For example,
int * A = new int[numofStudents];
Here A is a pointer to an array we just allocated using new. Even though A is a pointer to an array, it can be used as an array as A[i] etc.
Assume A now has the values indicating the number of movies watched by each student. So to calculate the mode of the values in the array you will call the function findMode as follows:
int m = findMode(A, numOfStudents);
The function should determine which value in the array occurs most often. The mode is the value the function should return. If the array has no mode (none of the values occur more than once), the function should return -1.
What is median and how do you calculate it? In statistics, when a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average , of the two middle values. Write a function called findMedian that accepts as arguments the following:
a. An array of integers.
b. An integer that indicates the number of elements in the array.
The function should determine the median of the array. This value should be returned as a double.
For example:
double median = findMedian(A, numberOfStudents);
To sort an array, you have to call the sort function as shown below.
If A is the array to be sorted and the array has numberOfStudents elements, then to sort the array do the following:
#include <algorithm> // include this along with <iostream> etc
%u2026.
%u2026.
sort(A, A+numberOfStudents); // call the sort function
%u2026.
Now you can look for middle value(s) in the array A.
Explanation / Answer
Mean:
The mean of a set of numbers is the average. The mean is calculated by finding the sum of all the values and dividing by the number of values.
11+12+12+13+14+16+18+19+20 = 135
There are 9 numbers in the series, so the mean is:
Mean = 135/9 = 15
A quick way to check if your answer is reasonable is to see if your answer is somewhere between the lowest and greatest number in the series. In our case, 11 is the lowest and 20 is the greatest. 15 is between the two.
Median:
The median of a series of numbers is the number that appears in the middle of the list when arranged from smallest to largest. For a list with an odd number of members, the way to find the middle number is to take the number of members and add one. Then divide that value by two. In our case, there are 9 numbers in the series. 9+1 = 10 and half of 10 is 5. The fifth number in the series is the median or 14.
If the number of members of the series was even, the average of the two middle numbers would be the median.
Mode:
The mode is the number in the series that appears the most often. If there is no single number that appears more than any other number in the series, there is no value for the mode.
The number 12 appears twice in the series. The mode of this series is 12.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.