CS 210 ­ Fundamentals of Programming I Spring 2013 ­ In­class Exercise 6 for 02/18/2013 & 02/19/2013

advertisement
CS 210 ­ Fundamentals of Programming I
Spring 2013 ­ In­class Exercise 6 for 02/18/2013 & 02/19/2013
(10 points) This exercise consists of both a coding part to completed during the lecture and a written part. The purpose of this exercise is to work with arrays and files. Write the answers to the written part in this assignment sheet. Hand in this sheet and submit the program electronically when you are done. An empty CodeBlocks project should be created for this exercise and the program file arrays.c and the datafile input.txt should be downloaded from the course website to the project folder, then added to the project.
Problem Statement
Write a program that will read temperature readings from a data file into an array until the end of the data is reached (marked by a negative sentinel value) or the array is full. Then it finds and displays the highest temperature in the array. The maximum number of readings in the file is 20.
Analysis & Design of Main Program
Provided in the file arrays.c and during class.
Function fill_array_from_file
This function reads (real) numbers from a file, counts them, and put them into an array. The end of the data is indicated by ­99. The function should not attempt to store more values than the array capacity. The analysis and design of this function will be presented during lecture.
Function print_array
This function displays the elements stored in an array. The analysis and design of this function will be presented during lecture.
Function find_maximum_element
This function finds and returns the largest element in an array. The analysis and design of this function will be presented during lecture.
02/16/2013
Page 1 of 2
D. Hwang
Name:________________________
CS 210 ­ Fundamentals of Programming I
Spring 2013 ­ In­class Exercise 6 for 02/18/2013 & 02/19/2013
Assignment Answer the following questions about this program. a. What is the type of the elements of the array temperatures? b. What is the maximum number of elements we can store in the array temperatures? c. What will happen if the file input.txt has 100 temperature readings in it?
d. How could you modify the program so that it would handle up to 100 temperature readings? e. Why doesn't the array parameter an_array of fill_array_from_file have an * even though it is a passed back parameter like the integer parameter element_count? f. What is the purpose of const in the parameter list of find_maximum_element? When you have completed this exercise, please fill in your name in the comment at the top of your arrays.c file, zip it up, and submit it under assignment 11­IN6 as usual, and turn in this exercise sheet with your answers to the questions. The submission system will compile, but not run, the program. Reminder: if you get done before the end of the class period, you are expected to work on Programming Assignment 4.
02/16/2013
Page 2 of 2
D. Hwang
Download