finding mean median and mode using arrays

Can I please have some assistance with the following program.
Given the following input file:
4 9 7 6 7 6 9 4 5 3 4 8 9 4 9 5 8 4 3 2 3 6 8 8 2 6 1 4 2 3 2 3 1 7 6 7 1 4 8 6 6 3 2 5 4 1 7 2 2 1 1 4 6 8 1 6 4 1 7 3 4 7 5 4 4 2 8 4 3 7 9 8 7 1 1 8 8 8 7 1 8 7 2 2 6 2 7 7 3 3 1 4 9 3 5 1 2 1 4

Determine the mean, median, and mode.
Implementation:

Use at least four (4) programmer defined functions; this excludes sort. At least three (3) must be void. Display unsorted array, sorted array, mean, median and mode (response frequency/histogram). All output should be displayed in the main program with the exception of mode (response/frequency histogram).

User should be prompted for input file name. Only 40 integers of sorted and unsorted arrays should be printed on one line. Please use a constant for size of array. In this file you can use a size of 99. ( const int SIZE=99) your question here.

Which bit(s) of the program are you stuck on?
Start by thinking about the data that you'll need. In this case you need the array, and the number of elements actually in the array:
1
2
3
const int SIZE=99;
unsigned numItems;
int numbers[SIZE];


Now what sort of things do you need to do:
- read the array
- sort the array (to find the mode and median)
- find the mode
- find the median
- find the mean

Some/all of these will probably turn into functions.

Now reread the assignment. See if you've missed anything or if you have any questions. As I re-read it I find:
- display unsorted and sorted array.
- at least 4 functions, at least 3 returning void.
- all output displayed in main program
- Prompt user for input file.
- when printing array, max of 40 per line.

- Question: what does prof mean by "response/frequency histogram"? Do you need to display a histogram of the data?

Now write prototypes for some functions and comments that describe what they do. Create the main program and write a series of comments to describe what it will do Can it do everything it needs to?

Read the assignment again and repeat the previous step Keep going until you're pretty sure you have everything you need.

Now you just have to fill in the code underneath your comments.
i have this so far
int main()
{
int input;
const int SIZE = 99;
int NumberOfEntries = 0; //Number of entries
int array[SIZE];

}
//function to find the mean that should be called by main()
double Mean (int NewArray[], size_t size)
{
double sum, mean = 0.0;

for (int i = 0; i < size; i++)
{
sum += NewArray[i];
}
mean = ((double)sum)/size;

return mean;
}

//function to find median that should be called by main()
double median;
{

if(size % 2 == 0)
{
median = (NewArray[size/2] + NewArray[size/2-1])/2.0f;
}
else
{
median = NewArray[size/2];
}
return median; //return median to main()
}


Sort(int NewArray[], size_t size)
{
for (i = 0; i < size; i++)
{
for(int j = 0; j < size-1; j++)
{
if(NewArray[j] > NewArray[j+1])
{
int temp = NewArray[j+1];
NewArray[j+1] = NewArray[j];
NewArray[j] = temp;
}
}
}
}
the response histogram is something like this

its like a table


Response Frequency Histogram

1 14 **************

2 12 ************

3 11 ***********

4 16 ****************

5 5 *****

6 10 **********

7 13 *************

8 12 ************

9 6 ******
Topic archived. No new replies allowed.