Laboratory Exercises For Computer Science 195

Files in C

Goals: This laboratory provides experience retrieving data from text files using C.

Text Data File

The file ~walker/151p/labs/lab26.dat contains several items of information about large American cities. More specifically, in ~walker/151p/labs/lab26.dat, each entry consists of the name of the city (line 1), the county or counties (line 2) and the state (line 3) in which it is situated, the year in which it was incorporated (line 4), its population as determined by the census of 1980 (line 5), its area in square kilometers (line 6), an estimate of the number of telephones in the city (line 7), and the number of radio stations (line 8) and television stations (line 9) serving the city. Thus a typical entry reads as follows:

   Albuquerque
   Bernalillo
   New Mexico
   1891
   331767
   247
   323935
   14
   5

A blank line follows each entry, including the last.

Work to turn in:

Processing Data in Files

Consider the following questions about the cities represented in the data files:

  1. Which of these cities listed in the file were incorporated more than 150 years ago?
  2. Which of these cities has the highest population density (population divided by area)?
  3. Which of these cities has more than 1 million telephones?
  4. Which of these cities has the lowest per capita number of radio and TV stations?

Program file.c contains stubs for procedures for these questions.

Work to turn in:


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/courses/195.fa01/lab.files.html

created September 27, 2001
last revised November 19, 2001
Valid HTML 3.2!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.