CMSC 106 Project #7 Fall 2001


Due date: Monday, December 10, 2001

1. Purpose

In this project you will write a program using structures, structures which contain other structures as members, arrays of structures, and functions with structure parameters, using both call-by-value and call-by-reference.

For this project you will be managing a database of weather data. You will read in and store the data using the definitions and rules from Project 6, and then you will process a series of requests to query and analyze the data. Although this project is extremely similar to Project 6 (in fact identical in some ways), you might find it easier to not reuse the code you wrote in Project 6. Why is that? The reason is that this is a new and completely different IMPLEMENTATION of that project, and the variables used to store the data (the important ones, not the ones like loop control variables) are completely different from those used in Project 6. You can reuse the CONCEPTS and algorithms used in Project 6. If your functions in Project 6 are well-organized, you may be able to rewrite them using the structures in this project; otherwise you should rewrite this project from scratch.

2. Project description

As you read this section, you may also want to refer to the ``Sample output'' section below.

2.1 Program input

The input data file will consist of three sections. The first two sections will consist of a station list and data report list formatted as described for Project 6. The only difference in these sections will be that the report list will end with a line containing a station identifier ``####''. There may or may not be additional data on this last report line.

Following the data reports, there will be a new section containing commands. Commands will be in the form:



operation data_item location_list

where "operation" is an action to be performed on the specified "data_item" for "location_list", a list of one or more locations. The operations are:

The data items are:

The locations in the location list may consist of either 2-character or 4-character symbols. If the symbol contains 2 characters, it represents a state. The symbol "US" represents all states for which data reports have been read. If the symbol contains 4 characters, it represents a specific station ID. The locations in any single command will be either all states or all individual stations. If the symbol is "US", it will be the only location on that command. An example of one command would be:


list wind MD DC

The items on this line will be separated by white space (one or more blanks) and there could be blanks at the beginning or end of the line. The operations and data items will be all lower-case. The locations will be all upper-case. The list of commands will end with the end of the input file. The actions to be performed for each operation are described in the "Processing and output" section below.

2.2 Processing and output

The program will read and process the station list and data reports as described in Project 6, except that the station and report data will be stored in STRUCTURES, as described below. After the data reports have been read and processed, the program will read and process each command, rather than printing the data summary as in Project 6. The output of each command should be preceded by a blank line, followed by a separator line containing 20 equal signs ("="). The commands are applied to locations as follows:

where SSSS is the symbol for the station.

The commands are processed as follows:

2.3 Program limits and assumptions


3. Project requirements

All your C programs in this course should be written in ANSI C, which means they must compile and run correctly with cc -std1 -trapuv on the OIT UNIX Class Cluster. You will lose credit if your program generates any warning messages when it is compiled. Prototypes must appear for all functions used, listed at the top of the program file.

You may use any ANSI C language features we have discussed in the course so far, plus anything we will discuss between now and the end of the semester, with the following exceptions:


Using any of these disallowed C features will result in losing credit.

Your program must define four structure types, as described below, which must be named exactly as shown. Your structures must contain the data items specified, but can have additional data fields besides these if you want. Unless otherwise specified, you may choose the type of any structure fields, but all numeric values must be defined as int or float. You may also define additional structure types and declare arrays of structures.


Station:
Wind:
Sky:
Report:

Your program must contain (and use) at least eight separate structure functions. A structure function either has a structure as a parameter, a structure as its return value, or has a pointer to a structure as a parameter. Your program must have at least one such function for each of the four required structures. To get more practice using functions with structures, and to make your program easier to develop and test, it is highly recommended that you write more than eight structure functions (that you write as many as possible). At least two of your structure functions must use call-by-value for their structure parameter(s) or must have a structure as their return value. At least two of the functions must use call-by-reference for their structures, so they must have pointers to structures as parameters, and they access the structures through the pointers.

If your program doesn't contain, and call, at least eight structure functions, of the types indicated, it will be graded as if it does not work on the primary input- even if its output is correct.

You may also write functions which don't operate on structures, as you like.

Here are some suggestions for possible structure functions; feel free to use others:


Your program must have a comment near the top which contains your name, login ID, student ID, your section number, your TA's name, and an original description of the action and operation of the program. Do not put your alias in this comment! In addition, you must have a comment before each function, explaining its action and operation. Your program should be written using good programming style and formatting, as discussed in class and throughout your textbook. For this project, style is considered to consist of:


4. Developing your program

You may want to skip this section at first, read the rest of the project, and come back to study it carefully when you are about to begin writing your program.

The more you write functions to perform various manipulations on structures, the easier your code becomes to test. You can use either call-by-value or call-by-reference for structure functions, but you have to have the indicated number of functions of each type. It is really recommended you use functions for each separate, discrete operation to be performed on any structure.

Do not use a global structure variable or array, like your book does in its example in Chapter 16! You will lose substantial credit if you use global variables in your project.

4.1 Possible development steps

It is extremely useful to first develop your program to work for simple cases of input. When it works perfectly for these, you can add code to handle the more complex situations one at a time. For this project, this might mean first developing your program for a simple input data file with just one valid command. You can create several such files, with one command of each type, making sure your results are correct for each. When you have thoroughly tested the different situations which can occur for the various commands and the results for all of them are fine, you can create a larger input file with several commands of different types.

This outline is a suggestion only; you do not have to follow it. There are many ways to develop any program. However, whatever steps you do choose in developing your project, you should be certain to write small parts of your program at a time and test each one to verify that it works before going on!


  1. To get more practice with structures, it might be a good idea to first define just the Station structure type. It contains several fields, but is much simpler than the Report structure, which contains other structures. You might also write a function which initializes a variable of this type of structure, using either call-by-value (returning a new structure with appropriate values in its fields) or call-by-reference. Declare a variable of this type, and call this function on it. Store some new values into the appropriate fields of your structure and print the values in all its fields, to verify you are manipulating structures correctly.

  2. Create functions to read and print the information from the station list and the report list. Make sure everything is being read and printed correctly before you try to do processing of commands.

  3. Create several simple input files

  4. Go back and read the project description above to identify the other cases and situations which have to be handled. Add code for each of these, compiling and checking after each one.

  5. Lastly, thoroughly check your entire program after finishing it before submitting it.

4.2 Finding compilation errors

If you get an error from the first line of your first structure function, which identifies a syntax error right after the name of the structure type, you probably have declared the structure type after this function which uses it. All structure type definitions must precede the first use of a variable or parameter of that structure type.

Here are several other common compilation errors having to do with structures produced by the cc compiler on our class machines and what they mean:


4.3 Program debugging


  1. Add lots of debug printf statements if your code isn't working, to find out where! You need to know this before you can find out why the problem is occurring.

  2. Draw lots of pictures of your structure types to trace exactly where things are in memory.

  3. If after you have tried these techniques, and tested each of your functions, you still can't figure out why your program doesn't work, bring a printout to our office hours, and we can help you learn how to track the problem down.

4.4 Helpful hints

Frequently save backup copies of your program under different names or in different subdirectories, so even if you inadvertently delete your file or change things which you realize you shouldn't have, it's easy to recover a recent version.

5. Academic integrity statement

Any evidence of unauthorized use of computer accounts or cooperation on projects will be submitted to the Student Honor Council, which could result in an XF for the course, suspension, or expulsion from the University. Projects are to be written INDIVIDUALLY. For academic honesty purposes, projects are to be considered comparable to a take-home exam. Any cooperation or exchange of ideas which would be prohibited on an exam is also prohibited on a project assignment, and WILL BE REPORTED to the Honor Council.


VIOLATIONS OF ACADEMIC HONESTY INCLUDE:


  1. failing to do all or any of the work on a project by yourself, other than assistance from the instructional staff.

  2. using any ideas or any part of another student's project, or copying any other individual's work in any way.

  3. giving any parts or ideas from your project, including test data, to another student.

  4. having programs on an open account or on a PC that other students can access.

  5. transferring any part of a project to or from another student or individual by any means, electronic or otherwise.


IT IS THE RESPONSIBILITY, UNDER THE UNIVERSITY HONOR POLICY, OF ANY STUDENT WHO LEARNS OF AN INCIDENT OF ACADEMIC DISHONESTY TO REPORT IT TO THEIR INSTRUCTOR.

6. Submitting your project

Your project must be electronically submitted by the date above, to avoid losing credit as described on the syllabus. No projects more than two days late will be accepted for credit without prior permission or a valid medical excuse, as described on your syllabus. Only the project which you electronically submit, according to the procedures provided, can be graded; it is your responsibility to test your program and verify that it works properly before submitting. Lost passwords or other system problems do not constitute valid justifications for late projects, so do not put off working on your program or wait to submit it at the last minute!

Turn in your assignment using the ``submit'' program as before, except using ``7'' for the project number. You are to submit only the .c file containing your source code, not the executable version of your program! If your program is in a file named ``reports.c'', submit would be run as submit 7 reports.c.

Before you submit your project, you must exactly follow the specific submission checklist in the ``Testing projects before submitting'' handout separately posted by your instructor!


7. Sample output

Assuming the name of the executable version of the program is ``reports.x'', here is a sample execution for one set of input. The information contained in the input file is shown as displayed by the UNIX ``cat''command. Following the data file's contents, the results of running the program with input redirected from that file are shown.

Be sure to test your program against a variety of inputs, so you are sure it works in all circumstances!

% cat p7.in1

KDCA Washington National, DC
KBWI Baltimore-Washington International, MD
KADW Andrews Air Force Base, MD
PADK Adak, AK
PANC Anchorage International, AK
PAFA Fairbanks International, AK
KMSP Minneapolis-St. Paul, MN  
KDLH Duluth International, MN
KPIH Pocatello, ID
KCYS Cheyenne Airport, WY
KADW Andrews Air Force Base, MD
KRDD Redding Municipal Airport, CA
KEUG Eugene, OR
KCQT USC Campus Downtown Los Angeles, CA
####
KMSP 061453Z 24009KT 6SM HZ BR FEW250 14/11 A3000 RMK AO2 SLP160 T01390111 53010  
KPIH 061456Z 00000KT 10SM -RA BKN070 OVC090 05/04 A3004 RMK AO2 RAE08B50 SLP165 P0000 60000 T00500039
KADW 061255Z 32009KT 7SM FEW040 08/02 A3020 RMK WND DATA ESTMD SLP231 8/100 9/100
KDCA 061351Z 34011KT 10SM CLR 07/02 A3023 RMK AO2 SLP235 T00671022
KCYS 080256Z 36017KT 9SM -SN FEW010 OVC040 M01/M03 A3046 RMK AO2 PK WND 36028/0233 SLP305 SNB21 P0000
KMSP 112140Z 20011G18KT 2SM RA BR FEW013 BKN020 OVC029 15/14 A2994 RMK AO2 P0002
PADK 052258Z 25020G35KT 9SM FEW018 BKN040 OVC050 04/00 A2939
KBWI 061354Z 31011G17KT 10SM CLR 06/M03 A3019 RMK AO2 SLP223 T00611028
KCQT 082347Z VRB03KT 4SM HZ CLR 22/14 A3004 RMK AO2 SLP170
KBWI 241754Z 10003KT 1SM BR OVC002 13/13 A3023 RMK AO2
####
list all DC CA
average temperature MD WY
list all KBWI
list temperature KMSP KPIH KCQT
average temperature KMSP KPIH
 

% reports.x <p7.in1

Duplicate station KADW

====================

Location:          USC Campus Downtown Los Angeles
Date/Time:         11/8, 2347
Wind:              variable at 3 KT
Visibility:        4 mile(s)
Sky conditions:    Clear
Weather:           Haze
Temperature:       22 C
Dew Point:         14 C
Pressure:          30.04 in.

Location:          Washington National
Date/Time:         11/6, 1351
Wind:              from 340 degrees at 11 KT
Visibility:        10 mile(s)
Sky conditions:    Clear
Temperature:       7 C
Dew Point:         2 C
Pressure:          30.23 in.

====================

  9.0 MD
 -1.0 WY

====================

Location:          Baltimore-Washington International
Date/Time:         11/6, 1354
Wind:              from 310 degrees at 11 KT, gusting to 17 KT
Visibility:        10 mile(s)
Sky conditions:    Clear
Temperature:       6 C
Dew Point:         -3 C
Pressure:          30.19 in.

Location:          Baltimore-Washington International
Date/Time:         11/24, 1754
Wind:              from 100 degrees at 3 KT
Visibility:        1 mile(s)
Sky conditions:    Overcast at 200 feet
Weather:           Mist
Temperature:       13 C
Dew Point:         13 C
Pressure:          30.23 in.

====================

22.0 USC Campus Downtown Los Angeles CA
 5.0 Pocatello ID
14.0 Minneapolis-St. Paul MN
15.0 Minneapolis-St. Paul MN

====================

 5.0 Pocatello ID
14.5 Minneapolis-St. Paul MN



For this project, the primary input consists of the contents of the file shown above. This file will be posted in your instructor's class posting account- do not try to type it in yourself! The primary output consists of all the data values in the entire output shown above. Note that this primary input does not exercise a number of conditions discussed above which your program should work for in order to earn credit for the secondary inputs.



Steve Scolnik
2001-11-29

Web Accessibility