Write a program to compute the aritmetic mean (average), median, and mode for up to 50 test scores. The data are contained in a text file. The program will also print a histogram of the scores.
The program should start with a function to read the data file and fill the array. Note that there may be fewer than 50 scores. This will require that the read function return the index for the last element in the array.
To determine the average. To determine the median, you mst first sort the array. The median is the score at last / 2 if last is an even inde and by averaging the scores at the floor and ceiling of last / 2 if last is odd. The mode is the score that occurs the most often. It can be determined as a byprodcut of building which score occurred most often. (Note that two scores can occur the same number of times.)
This is what I came up using Bloodshed Dev-C++:
#include <stdio.h>
#include <stdlib.h>
double average (int ary[ ]);
void printAverage (int data[ ], int size, int lineSize);
int main (void)
{
double avg;
int base[50] = {30, 70, 20, 40, 50, 10, 90, 80, 40, 100,
90, 30, 60, 80, 20, 90, 100, 50, 30, 20,
70, 10, 50, 70, 90, 20, 10, 90, 50, 80,
40, 90, 20, 20, 30, 40, 60, 50, 70, 90,
100, 20, 30, 40, 50, 60, 70, 80, 90, 90};
avg = average(base);
printAverage (nums, size, 10);
system ("pause");
return 0;
}
double average (int ary[ ])
{
int sum = 0;
for (int base = 0; base < 50; base++)
sum += ary[base];
return (sum / 5.0);
}
void printAverage (int data[], int size, int lineSize)
{
int numPrinted = 0;
printf("\n\n");
for (int i = 0; i < size; i++)
{
numPrinted++;
printf("%2d ", data[i]);
if (numPrinted >= lineSize)
{
printf("\n");
numPrinted = 0;
}
}
printf("\n\n");
return;
}
Any advice or tip will help out. Thank you