ITEC 320: Program 1


Due by 11:59:59 p.m., Tuesday February 2, 2010

Submit command for Dr. Okie's section: submit itec320-01 clusters.adb

Dr. Uppuluri's section turn in the program using Web CT


Your assignment is to write a program called clusters that does some analysis of an increasing sequence of positive integers. You are to recognize clusters of integers and output information on each cluster and on all clusters. The integers might represent, for example, the times at which some event occurs, and the events might occur in clusters.

Sample Run: Assume that this sample input data is in the file p1.dat:

4 15   16
        1016   1017   

        1020   1021   1022   
    1110 1111 1113  1116 1125  1126 1136

100000000 100000001 
0
Assume that the program is executed, with the input redirected from the input file, as follows:
clusters < p1.dat
Then this will be the resulting output:
Cluster 1
    Size: 3
    Range: 12
    Average gap size: 6.00

Cluster 2
    Size: 12
    Range: 120
    Average gap size: 10.91

Cluster 3
    Size: 2
    Range: 1
    Average gap size: 1.00

Number of clusters: 3
Largest size:  12
Second largest size: 3
Average of average gap sizes: 5.97
Weighted average of average gap sizes: 9.50

Input specification:

  1. Data points are increasing positive integers.
  2. The last data point is followed by 0 which marks the end of the input.
  3. An integer starts a new cluster if it differs from the previous integer by 1000 or more.
  4. Integers are separated by white space.
  5. Each integer can be surrounded by any amount of white space.
  6. All values, partial results, and results will fit in 32 bit variables.
  7. The input will be valid.
  8. There will be at least 2 clusters and each cluster will have at least 2 elements.
  9. Your program is to read from standard input (which is the default for get).
Output specification: For each set, your program should output the information shown in the sample run. After processing all of the sets, your program should also display the summary information shown in the sample run:
  1. Your output should follow the format of the example exactly, including blanks.
  2. Your program is to have no prompts.
  3. Each line of output should include a label, a colon, a single blank, and the relevant number.
  4. Floating point values should be output with two places to the right of the decimal point.
  5. Data on individual sets should be indented 4 spaces.
  6. There are to be no trailing blanks on the lines.
  7. A blank line (ie containing only a line separator) should appear after the output for each set.
  8. Your program is to write to standard output (which is the default for put)
Other points
  1. Your program should be called clusters.adb
  2. Input numbers using numeric I/O, not by reading the input as one or more strings.
  3. Any data files that you use can be created with any editor, but make sure that you create your data file on the same OS that you use to compile and run your program. You do not need to submit your data file.
  4. Your program should read from standard input and write to standard output, which is the default for get and put. Do NOT use a file that is named in your program for input.

Grading criteria: When grading I will check the following specifications:

Standard input: Your program is to read from standard input. Please do not get input from a file whose name is coded in your program. Normally standard input reads from the keyboard.

For your own benefit, you should test your program using a set of test cases that are stored in a file. To cause standard input to read from a file you must use redirection. For example, to cause it to read from a file named myData.txt, you would enter the following on the command line:

clusters < myData.txt
If you are using Adagide, you can cause standard input to come from a file by using the "Run/Run Options" dialog. Select your input data file and check the "Redirect input" box.

Please remember that if you put your data in a file, then end_of_file is automatically detected after the last character in the file has been reached - you do NOT put a control-D or a control-Z into the file! Also remember that your data file needs to be created using the same operating system that you use to create your file.

Marking End of File on Interactive Input: If you want to test your program with data from the keyboard (ie with standard input reading from the keyboard), then you will need some way of signaling the end of the input. We call this signaling end of file even though there is actually no file when you do interactive input.

The way you signal end of file depends on the operating system. On unix/linux systems, the function end_of_file returns true when you type ^D (ie hold down control and press D, aka control-D) on a separate line. On MS Windows systems, end_of_file returns true when you type, on a separate line, ^Z followed by an enter. Please remember that when reading from a file, the OS recognizes when the input is at the end of file, and so you do NOT put a control-D or control-Z into the file!

Of course, to run your program so that standard input reads from the keyboard, you simply enter its name as a command (eg clusters).

Style: Your program should follow my style guide. In particular, please note the use of consistent indentation, named constants, and descriptive constant and variable names. Please remember that the first thing in any program file should be a comment that gives a brief overview of what the file contains (and should do). Also remember to keep your lines less than 80 characters long. Not only does this mean that printouts won't run off the side of the page, but it also makes your programs look neater on an 80 column wide xterm window (a popular size). Please ask if you have questions about style.

Submission: Use the submit command to turn your program in for grading. You may submit as many times as you like, but only the last submission is kept. In particular, be aware that since only the last submission is kept, if the last one is late, then your assignment is late and will thus receive a late penalty. Also remember that you must be on rucs2 for submit to work. To submit your work for grading do the following:

   submit itec320-01 clusters.adb
Next assignment

Dr. Okie's Home Page,
Last modified on Monday, 25-Jan-2010 15:26:10 EST