C.I.S. 1.5 (Science Section)

Brooklyn College

Professor Langsam

 

Assignment #5

 

This assignment will compute statistics using data collected by a weather balloon. The weather balloon collects information about the temperature and humidity.

 

The main program should first read (from an input file) the number of data points collected (the header value), n. The main program should verify that n has a valid value.

 

Then the main program should call a function called readData which will read the data values from the input file. The data should be read into two arrays – one called temperature and the other called humidity. There will be n values in each of the two arrays.

 

For example, a set of data might consist of:

 

                        3

                        72.5                 50.4

                        75.2                 62.4

                        78.9                 55.3

 

Where 3 is the header value and there are 3 values in each array.

 

The values 72.5, 75.2 and 78.9 go in the temperature array. The values 50.4, 62.4 and 55.3 go in the humidity array.

 

Your program should call a function printArray twice. First, it will be used to print the contents of the temperature array; then it will be used to print the contents of the humidity array. The function printArray should receive three parameters – an output file, an array and a value n.

 

The main program will then call the functions maxArray, minArray, meanArray, medianArray and stdDevArray, described below. Each of these functions will be called twice - once for the temperature array and once for the humidity array. Each of these functions will return an answer to the main program, and the program should print these answers, together with appropriate messages, to the output file.

 

maxArray – returns the maximum value stored in the array. The function receives two parameters – an array and a value n.

 

minArray – returns the minimum value stored in the array. The function receives two parameters – an array and a value n.

 

meanArray – returns the mean (average) of the values stored in the array. The function receives two parameters – an array and a value n.

 

medianArray – returns the median of the values stored in the array. The function receives two parameters – an array and a value n.

 

standardDeviationArray – returns the standard deviation of the data stored in the array. The function receives two parameters – an array and a value n.

 

The mean is the average and is defined by:

 

 

 

The standard deviation is:

 

 

The median is the value such that half of the scores lie above it and half of the scores lie below it. To find the median, the function median calls a function sort which sorts the first n elements of the array x. After sorting, the median is the middle number (if n is odd), while it is the average of the two middle numbers if n is even.

 

Finally, the main program will call a function countValue to count how many times a specific value appears in each of the two arrays. To do this, the main program will read in a series of values from the input file (the same one as used before), until it reaches eof. For each value read in, it will call countValue twice, once to find out how many times it appears in temperature, and once to find out how many times it appears in humidity. The function countValue receives three parameters – the array, the value n, and the value that it is counting. The function will return the count, and the main program will print the answer together with an appropriate message.

 

All output is to be to a file. Be sure to use the structured programming techniques discussed in class as well as meaningful variables and appropriate comments. Submit your program and input and output files.

 

Use the data file found here: http://eilat.sci.brooklyn.cuny.edu/cis1_5/CISClassPage.htm


For example, given the following input file:

                       

            3

            72.6                 50.4

            75.2                 62.4

            78.9                 55.3

            72.6

            62.4

            85

            92

 

Your output file should appear as follows:

 

3 data sets.

 

The temperature array contains: 72.6                 75.2                                                    78.9

The humidity array contains:        50.4                 62.4                                                   55.3

 

The lowest temperature value is: 72.6

The lowest humidity value is: 50.4

 

The highest temperature value is: 78.9

The highest humidity value is: 62.4

 

The average temperature value is: 75.5

The average humidity value is: 56.03

 

The median temperature value is: 75.2

The median humidity value is: 55.3

 

The standard deviation of the temperature values is: … (I didn't figure it out)

The standard deviation of the humidity values is: …

 

72.6 was found 1 time(s) in the temperature array 72.6 was found 0 time(s) in the humidity array

62.4 was found 0 time(s) in the temperature array 62.4 was found 1 time(s) in the humidity array

85.0 was found 0 time(s) in the temperature array 85.0 was found 0 time(s) in the humidity array

92.0 was found 0 time(s) in the temperature array 92.0 was found 0 time(s) in the humidity array