Under your cisc105 subdirectory, make a new directory for lab04, just like we did for lab04 last week (see last week's lab if you are not sure what to do).
You might want to just copy all the files from that subdirectory into your current directory. Here's a sequence of commands that will both create a new subdirectory for lab04, and copy all the files you will need into it:
cd ~/cisc105
cp -r ~pconrad/public_html/cisc105/04F/labs/lab04 .
cd lab04
This will first change your current working directory to your cisc105 subdirectory,
then copy the entire lab04 subdirectory from my account, along
with all its contents, into the current directory. You'll then have to cd into lab04 to
see all the files. The -r stands for recursive, and the "." at
the end of the second command is a symbol meaning "the current directory
is the target of the copy command".
(Note: This command might just show up on an exam, so be sure you understand how it works!)
A common problem, when faced with a data file, is to find the highest and lowest values in the data.
For the first part of this lab, you will have a data file
integers.dat containing an unknown number of
integers. The file ends with the value -1, which is a "sentinel value"
(not a part of the actual data, but just a number that marks the end
of the data.) You will read the integers from the file one at a time,
and compare them against high and low values that you have already
read. As you read each new number, adjust your high and low variables
accordingly.
Remember that you cannot compare a variable against another unless they both have been assigned values. Given that restriction, how will you start your high and low variables off? One common, but poor, solution is to give the variables arbitrary values that seem very high or low. This is problematic because it limits what data the program will work for. You must use a better way of initializing your variables.
Your program must read data from the file until it reads the value -1, which will be the last number in the file. This kind of special value is called a sentinel value. It is important to choose a sentinel which cannot appear in your data set (do you see why?). Since our data are restricted to positive numbers, we can use -1 as a sentinel value.
Your program will print out the total number of integers read before the sentinel, the highest integer, and the lowest integer.
Can you solve this problem by yourself? If so, write down your ideas
before you look at min.c. Is your solution the same? If not,
look at how they differ. Do they perform the same task? Initialize the
same way? Have the same efficiency in time and memory use?
min.c, then put it away. If you need to
peek at it later, go ahead, but you need to internalize the ideas in
this program.
Now that you have a general idea of the method, you can expand the same concepts to a new problem domain. waypoints.dat is a data file containing information about geographic locations and their altitudes. Your job is to identify five attributes of the data:
The location coordinates are in a reference system that is slowly replacing the use of latitude and longitude, called UTM (Universal Transverse Mercator). The easting number tells where something is ``side-to-side'' on the globe (like longitude); the northing number tells where it falls between the North Pole and the Equator.
You can tell where two points fall relative to one another by comparing the numbers. A larger easting number is further east than a lower one. Likewise a higher northing implies that a point is further North.
Your output should look like this:
> ./lab04b Westernmost point has easting 130581451 Easternmost point has easting 190505959 Southernmost point has northing 4057300 Northernmost point has northing 5307802 Highest point has altitude 7242 Count is 25 > |
Script file lab04a.txt should contain a listing, a compile, and a run of your lab04a.c program. Also cat the file integers.dat before you run the program.
Script file lab04b.txt should contain the same elements as lab04a.txt but for lab04b.c (of course, cat the waypoints.dat files instead of the integers.dat file).
Submit lab04a.c, lab04b.c, lab04a.txt and lab04b.txt to WebCT. Print your script files and submit to your TA on paper.
Grading:
lab04a.txt:
lab04b.txt:
Total 100pts