c programing homework
CEG 2170
Laboratory 7
1. (15 points) Write a program that calculates average precipitation for a number of days, given the daily
precipitation values in inches. The daily values will be in a file named precipitation.txt. The first line in
the file will be an integer which specifies the number of values to follow. Your program should read the
daily precipitation values into an array, print the array to the screen, calculate the average precipitation for
the period, and print the result to the screen. Allow for a maximum of 365 days of precipitation data. You
must use functions to:
Read the data from the file into an array. The array should be passed as an argument to the function, and the function should return the number of items that were read from the file.
Print the precipitation data to the screen. Calculate the average precipitation. The function should have the array as an argument, and should
return the average value.
2. (15 points) Write a program that manipulates a one dimensional array of integers. Use functions for all
tasks.
Generate an array of 50 random integers with values between 0 and 999.
Print the array to the screen.
Use qSort to sort the array (Note: qsort requires a comparison function , so you will need to write that function and use it as a parameter to qSort).
Print the array to the screen. Use bSearch to search the array for a target value input from the keyboard (also requires compare
function).
Print the results to the screen.
(Extra Credit: 5 pts - Guarantee that there are no duplicates in the array of random integers.)
3. (20 points) Write a program that reads, from a data file, information containing power output for an
electrical plant for an eight-week period and then calculates and output the average power per day and
the average over the eight-week period.. Each line of data contains seven values representing the daily
power output for a week. Read the data into a two dimensional array which has eight rows and seven
columns.
You must use functions to:
read the input data into the two dimensional array. The function should prompt the user to enter the filename from which the data will be read. The input file power.txt is provided on Pilot.
calculate the average power for a day (that is, the average of a row of the array), returning those results in an array named weekAverage (a 1D array with 8 elements).
calculate the average power for each day over the eight weeks (that is, the average of a column of the array), returning those results in an array named dayAverage (a 1D array with 7 elements).
print a report to the screen
print a report to a datafile. (The user should be prompted to enter the name of the output file.) The report should show the average power for each day of the week, one day per line, and the average power for a
week, one week at a time, formatted as shown on the next page. Note: This assumes the first value in
each row is for Sunday of that week, and that the days are in order – second value Monday, third value
Tuesday, etc.
Daily and Weekly Power Averages:
Sunday: Average = 441.72
Monday: Average = 424.67
Tuesday: Average = 403.97
Wednesday: Average = 397.98
Thursday: Average = 340.56
Friday: Average = 359.32
Saturday: Average = 308.11
Week 1: Average = 264.34
Week 2: Average = 399.26
Week 3: Average = 319.32
Week 4: Average = 338.16
Week 5: Average = 366.96
Week 6: Average = 392.59
Week 7: Average = 418.23
Week 8: Average = 559.80