ITEC 320: Program 1


Tentative Due Date: 11:59:59 p.m., Thursday, Feb. 1, 2018

Submit command: submit itec320-01 setops.adb


Last modified:
Updates:

  1. 2018 Jan 31 03:22:10 PM: Corrected average of averages line in assignment checker
  2. 2018 Jan 31 03:22:10 PM: Removed a space on the average of averages line in sample output
  3. 2018 Jan 24 03:56:42 PM: Corrected error in assignment checker
  4. 2018 Jan 24 03:56:42 PM: Added colon (ie ":") to Set line in sample run.
  5. 2018 Jan 24 09:43:49 AM: Added assignment checker


You can see an example of this program at assignment checker (which uses gnoga to integrate the GUI, web server, and problem solution). On-campus or VPN session required.

Your assignment is to write a program that analyzes sets of integers.

Sample Run:

Here is a sample run of the program. Assume that this sample input data is in the file p1.txt:

   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:
setops < p1.txt
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

Average of Averages: 8.27
Largest second largest: 29

Input specification:

  1. Input consists of zero or more sets.
  2. Each set is immediately preceded by a positive number that is the size of that set.
  3. A size of zero marks the end of the input.

  4. Each integer can be surrounded by any amount of white space.
  5. All values, partial results, and results will fit in 32 bit variables.
  6. Your program does not need to check for input errors.
  7. Your program is to read from standard input (which is the default for Ada.Text_IO.Get).
Output specification:

For each set you are to display the set's

  1. Sequence number (ie 1, 2, 3, ...)
  2. Size
  3. Average (printed with two decimal places)
  4. Second largest element (if there is one)

After processing all of the sets, your program should print a summary:

  1. The average of all of the averages, if there are any
  2. The largest of all of the second largest values, if there are any
Other points on the output:
  1. No second largest element is displayed if the set has no second largest.
  2. No largest second largest is displayed if there are no second largest elements.
  3. If there are no data sets, then your program should have no output.
Output format:
  1. Your output should follow the format of the example exactly, including blanks.
  2. Your program is to have no prompts.
  3. For each line, print 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
Other points
  1. Your program should be called setops.adb
  2. Read numbers using numeric I/O, not by reading the input as one or more strings.
  3. Make sure that your program reads from Standard Input, not from a file whose name is specified in the program.

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

  1. Read in sets until non positive size.
  2. I/O uses standard input and standard output.
  3. No prompts
  4. Correct set number, average, second largest (if one exists).
  5. Correct summary.
  6. Correct output format.
  7. Program works correctly with atypical data (ie no data sets)
  8. Style: Internal and block documentation and uses appropriate white space
  9. On time (10% per day late penalty, up until when graded)

Creating input files: For your own benefit, you should test your program using a set of test cases that are stored in files. Your data file can be created with any editor, but don't use an editor (such as wordpad) that stores characters using 16 rather than 8 bits. Make sure that your editor is not creating a RTF (ie rich text) file. You will want to make sure that you create your data file using the same OS that you use to test your program. When a data file is created on a different OS, the I/O routines may not correctly detect the end of file or end of line white space. You do not need to submit your data file(s).

Standard input: Your program is to read from what is known as Standard Input. Do NOT use a file that is named in your program for input. If you don't specify otherwise, a read from standard input comes from the keyboard. To cause standard input come from a file, you must use input redirection. For example, to cause the program to read standard input from a file named myData.txt, you would enter the following on the command line:

   setops < myData.txt

If you are using AdaGIDE, you must tell it to use redirection and to specify the file: use Run/Run Options, check the Redirect box, and enter the name of the file that contains the data. As far as I know, GPS does not allow redirection. Instead you must use a command line.

To read from standard input, your program can simply use a get such as get(x).

End of File on Interactive Input: If you want to test your program by giving it input from the keyboard, then you will need some way of signaling the end of the input, that is, signaling end of file (though there is no real file in this case). The way you signal end of file differs depending on the operating system. On unix/linux systems, the Ada function end_of_file returns true when you enter ^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 enter, 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!

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 rucs for submit to work. To submit your work for grading do the submit command given at the top of the assignment.
Next assignment


Dr. Okie's Home Page,
Last modified on