# How to complete program. Any probs now?

• 11-17-2003
stehigs321
How to complete program. Any probs now?
Hey, I am working on a program that takes in grades of students and find the mean and standard deviation, then prints a histogram. First in my post is the problem, then what i have now. Please help on what i need to add to complete this program to have it run smoothly. Thanks so much you guys.

Problem:::::

Background Information: This assignment pertains to statistical analysis for a given data sample. In statistics, a collection of data values is usually referred to as a distribution. A primary purpose of statistical analysis is to find ways to compress the complete set of data into summary statistics that express properties of the distribution as a whole.

Mean:
The most common statistical measure is the mean, which is simply the traditional average. For the distribution x1, x2, ¡K xn, the mean is usually represented by the symbol

Standard Deviation:
Another common statistical measure is the standard deviation, which provides an indication of how much the individual values in the distribution differ from the mean. To calculate the standard deviation whose elements are x1, x2, ¡K xn you need to perform the following steps:
a. Calculate the mean of the distribution.
b. Go through the individual data items in the distribution and calculate the square of the difference between each data value and the mean. Add all these values to a running total.
c. Take the total from step b and divide it by the number of data items.
d. Calculate the square root of the resulting quantity, which represents the standard deviation.
In mathematical form, the standard deviation (ƒã) is given by the following formula:
ƒã =

Histogram:
A histogram gives us a pictorial view of the data. Basically it is a frequency plot. For example given a histogram of a set of marks of students in a class, we can immediately see whether there were more students in the range 50-54 or 80-84 and so on. To draw a histogram, first decide upon the intervals. Let us say the interval is 5. Then count the number of students getting marks in the intervals 0-4, 5-9, 10-14, 15-19, 20-24, 25-29 and so on. The last interval will contain a single integer. Now you are ready to draw the histogram or the frequency plot. Here is an example of a histogram plot:

0¡V 4|****************
5- 9|***********************
10-14|******************************
15-19|*************************************
20-24|**********************
25-29|*************
30-34|*********
35-39|****
40-44|**
45-49|*
50|**

Your program should include the following functions:

/* This function reads an unknown number of grades (maximum of 100) into the array grades and counts the data items that have been read. You are not supposed to prompt the user to enter the grades. Just use scanf to read in the grades. The end of the input is represented by a negative number ¡V999 */
Preconditions: An empty array which is initialized to 0 must be passed to the function.
Postconditions: Array holds the input values and n is the effective size of the array (i.e the number of data items read) */

/* Given an array of real numbers, this function finds out frequency (number of students) for each interval 0-4, 5-9,¡K..,95 ¡V 99, 100 prints out the frequency values and plots the histogram */

/* Given an array of real numbers and the effective size of the array (i.e. count of the numbers in the array), this function returns the location of the highest number in the array */

/* Given an array of real numbers and the effective size of the array (i.e. count of the numbers in the array), this function returns the location of the lowest number in the array */

void deleteElement(double grades[], int *n, int loc);
/* Given an array of real numbers, the effective size of the array and the location of the element to be deleted, this function deletes that element from the array and decrements the effective size, n, by one */

/* Given an array of numbers and the effective size of the array this function computes and returns the mean */

/* Given an array of numbers and the effective size of the array, this function computes and returns the standard deviation as described in the previous section */

What i have::::
Code:

```void readGrades(double grades[], int *n); void frequency(double grades[]); int maximum(double grades[], int n); int minimum(double grades[], int n); void deleteElement(double grades[], int *n, int loc); double mean(double grades[], int n); double StandardDeviation(double grades[], int n);   int main() {     int n, loc, sum, i, min, max;     double grades[100], mean, deviation;   readGrades(grades, &n);   min = minimum(grades, n);   printf("The data has been adjusted by removing the minimum %d\n", min);    deleteElement(grades, &n, loc);   maximum(grades, n);   printf("The data has been adjusted by removing the maximum %d\n", max);   deleteElement(grades, &n, loc);   mean = mean(grades, n);   printf("The adjusted mean is %lf\n", mean);   StandardDeviation(grades, n);   printf("the adjusted standard deviation is %lf\n", deviation);   frequency(grades); }   void readGrades(double grades[], int *n) {     int i;   for (i=0; i<100; i=i+1){     scanf("%f", &n);     grades[i] = *n;     }     }   void frequency(double grades[])  {   }   int maximum(double grades[], int n)  {     int i, j, max = 0;       for (i = 0; i < n; i++ )       for ( j = 0; j < n; j++ )         if ( grades[i] > max )           max = grades[j];             return max;     }   int minimum(double grades[], int n)  {     int i, j, lowGrade = 100;       for ( i = 0; i < n; i++)       for ( j = 0; j < n; j++)         if (grades[i] < lowGrade)             lowGrade = grades[i];             return lowGrade;     }   void deleteElement(double grades[], int *n, int loc)  {     }   double mean(double grades[], int n)  {     int i, total = 0;       for (i = 0; i <= n - 1; i++)             total += grades[i];         return (double) total/n;     }   double StandardDeviation(double grades[], int n) {     }```
only error i have so far compiling is:::

stat.c.32: called object is not a function.

line 32 is where i have mean = mean(grades, n);
in main

• 11-17-2003
Ken.com

So, what is it that you really need help with? Are you having a problem printing the dist. graph, finding the std. dev, etc..
• 11-17-2003
R.Stiltskin
You have a double mean and a double mean() & I guess the compiler doesn't allow that. Change one of them.

Actually, I'm a little surprised that this is not allowed, since the function name has () & I would have thought that would allow the compiler to distinguish between them, but clearly the compiler is not allowing this duplication.

On the other hand, using the same name for a variable and a function is confusing to a reader of the program so it would be better to avoid this practice anyway, even if the compiler allowed it.
• 11-18-2003
stehigs321
What i need help with.
i need help with the standard deviation function, the deleteElement function (and make sure it works how it should in main), and having the frequency function work. The functions and descriptions of what they do are given. thanks so much guys
• 11-19-2003
stehigs321
Please help me with the standard deviation function, the deleteElement function (and make sure it works how it should in main), and having the frequency function work. The functions and descriptions of what they do are given. thanks so much guys. This should be simple but what are they?
• 11-19-2003
Salem
Well since we don't have access to " this function computes and returns the standard deviation as described in the previous section" I suggest you go away and read it again.

I'm curious as to how you've managed to produce this code and all of a sudden you're horribly stuck.

Here's a couple of other points

Perhaps you should do

Perhaps

3. this function returns the location of the highest number in the array
Look at your code for maximum
What you should really be returning is j (the position in the array), not the value at that position.

Also, your min/max loops are broken. It should be like this
Code:

```max = grades[0]; pos = 0; for ( i = 1 ; i < n ; i++ ) if ( grades[i] > grades[pos] ) pos = i; return pos;```
Deleting an element
This is so blindingly easy, its not worth explaining how to do it, so I'll just show you
Code:

```void deleteElement(double grades[], int *n, int loc) {     grades[loc] = grades[(*n)-1];     (*n)--; }```
1. Move the element from the end of the array to the indicated position
2. decrement the count
• 11-19-2003
stehigs321
What i have so far with errors.
Hey here is what i have so far. There are no compiling errors. but when i run the file if i enter a whole number like 2 i get an error right away that says "Segmentation fault (coredump)". if i enter a float number like 2.2 i get this error "Bus Error(coredump)". What do these mean.
Also what is a code to find the statndard deviation. given the array and the number of items in the array? thanks so much for helping me get this far u guys. Also anyone know how to make the histogram that was described in my first post??

Code:

```/*      Program Number: 6     Title: Statistical analysis     Date:  11-7-03 */ #include <stdio.h> void readGrades(double grades[], int *n); void frequency(double grades[]); int maximum(double grades[], int n); int minimum(double grades[], int n); void deleteElement(double grades[], int *n, int loc); double mean(double grades[], int n); double StandardDeviation(double grades[], int n);   int main() {     int n, loc, sum, i, min, max;     double grades[100], mainmean, deviation;     readGrades(grades, &n);     min = minimum(grades, n);   printf("The data has been adjusted by removing the minimum %d\n", min);      loc = min;   deleteElement(grades, &n, loc);   max = maximum(grades, n);   printf("The data has been adjusted by removing the maximum %d\n", max);   loc = max;     deleteElement(grades, &n, loc);   mainmean = mean(grades, n);   printf("The adjusted mean is %lf\n", mainmean);   StandardDeviation(grades, n);   printf("the adjusted standard deviation is %lf\n", deviation);     frequency(grades); }   void readGrades(double grades[], int *n) {   int i;       for (i=0; i<100; i++){     scanf("%lf", &n);     grades[i] = *n;     }   }   void frequency(double grades[])  {     }   int maximum(double grades[], int n)  {         int i, pos;            pos = 0;         for ( i = 0 ; i < n ; i++ )         if ( grades[i] > grades[pos] )         pos = i;         return pos;     }     int minimum(double grades[], int n)  {     int i, pos;     pos = 0;       for ( i = 0; i < n; i++)       if (grades[i] < grades[pos])             pos = i;             return pos;     }   void deleteElement(double grades[], int *n, int loc)  {     grades[loc] = grades[(*n)-1];     (*n)--;     }     double mean(double grades[], int n)  {     int i, total = 0;       for (i = 0; i <= n - 1; i++)             total += grades[i];         return (double) total/n;     }     double StandardDeviation(double grades[], int n) {     }```
• 11-19-2003
Salem
Get a better compiler - one which warns you when you make a mess of printf and scanf

scanf("%lf", &n);