ITEC 320: Program 1


Due by 11:59:59 p.m., Tuesday September 15, 2009

Due by 11:59:59 p.m., Monday September 14, 2009

Submit command: submit itec320-01 intsets.adb


Update 9/10/09:

  1. Changed the sample run to show that the output results from redirecting the input to read from a file. An interactive sample run would look somewhat different.
  2. Corrected average of the averages in the sample run.

Your assignment is to write a program called intsets that does some analysis of sets of integers. For each set you are to display the

After processing all of the sets, your program should also display: Each data set is preceded in the input with the size of that set. A non-positive set size marks the end of the input.

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

2 
6 
4
  4   10   40   20   29
3 -1 -2 -2
1 5
0
Assume that the program is executed, with the input redirected from the input file, as follows:
intsets < p1.dat
Then this will be the resulting output:
Set 1
    Size: 2
    Average: 5.00
    Second largest: 4

Set 2
    Size: 4
    Average: 24.75
    Second largest: 29

Set 3
    Size: 3
    Average: -1.67
    Second largest: -2

Set 4
    Size: 1
    Average: 5.00

Overall Average: 10.47 8.27
Largest second largest: 29

Input specification:

  1. Input is one or more integers, separated by white space.
  2. Each integer can be surrounded by any amount of white space.
  3. All values, partial results, and results will fit in 32 bit variables.
  4. The input will be valid.
  5. Your program is to read from standard input (which is the default for get).
Output specification:
  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. Data on individual sets should be indented 4 spaces.
  5. There are to be no trailing blanks on the lines
  6. A blank line (ie containing only a line separator) should appear after the output for each set
  7. No second largest element is displayed if the set has fewer than two members.
  8. No largest second largest is displayed if there are no second largest elements.
  9. Your program is to write to standard output (which is the default for put)
  10. If there are no data sets, then your program should have no output.
Other points
  1. Your program should be called intsets.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. The number of sets is non-negative but unknown, and processing is to continue until reaching a non-positive size.

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:

intsets < 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 intsets).

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 intsets.adb
Next assignment

Dr. Okie's Home Page,
Last modified on Friday, 11-Sep-2009 14:28:44 EDT