CSCI 360 Spring 2014

Program 5
Sorting and Internal Subroutines
(100 points)


Overview

For this assignment, modify program 4 so that it uses internal subroutines to build and print a table of numbers. A routine to sort the table of numbers will also be added.

After the table has been built, the table should be sorted and then printed three times. The first printing should display all of the numbers. The second and third printings will display the multiples of a specific value that is passed into the PRINT routine.

The Table

The table is the same as in Program 4.

Input

The input file has one extra record at the beginning of the file. The first record contains exactly two numbers. The first number is the multiple value for the second printing of the table. The second number is the multiple value for the third printing of the table. The remaining records in the file have the same data and format as the program 4 input file.

For example:

6  3
1 -2005 360  515   90 50  -1   114 240  172219    60205
3 7534  204914  141 0 606031     -419  218   111
...

The first record from the above example input file shows that the second printing of the table should only display multiples of 6 and the third printing should only display multiples of 3.

Internal Subroutines

For this assignment, code at least the following 4 routines:

MAIN

This routine will control the flow of the program by:

  1. Read the first input record from the input file and save the two values
  2. calling the routine to build the table
  3. calling the routine to sort the table
  4. calling the routine to print the complete table
  5. calling the routine to print the multiples specified by the first number on the first input record
  6. calling the routine to print the multiples specified by the second number on the first input record

The storage area for this routine is where the table, the fullword that holds the address of the next available entry in the table, the input buffer, and the report headers should be created.

BUILD

This routine will put the information into the table and set the address of the next available spot in the table.

Input Parameters for BUILD:

Suggested logic for BUILD

Initialization: Get the parameters
                Set the table pointer to 1st entry in table

Read the first record

While end of file has not been reached
  Move the data from the input record to the table using an XDECI loop
  Read the next record
Endwhile

Use the second input parameter to pass back the address of the next
   available entry in the table

PRINT

This routine will print the values in a table that are multiples of a passed in value.

As in program 4, the PRINT subroutine should display 7 values per line. However, it's possible that the last line of output could have less than 7 values.

Input Parameters for PRINT:

Suggested logic for PRINT

Initialization: Get the parameters and initialize any counters to 0

While end of the table has not been reached
  Get a number from the table
  If the number is a multiple of the passed in value

    Put the number on the print line

    If the print line is full
      Write the print line
      Clear the print line
    Endif

  Endif

  Increment the table pointer to the next entry in the table
Endwhile

If there are numbers on the print line
  Write the print line
Endif

SORT

This routine will sort the contents of the table using the SELECTION SORT algorithm that is given in the course notes. The records should be sorted in ASCENDING order.

Input Parameters for SORT:

Suggested logic for SORT

for TOP from start of table to end of table; one entry at a time
  Set the Subscript of smallest entry to TOP

  for Work subscript from TOP + 1 to end of table; one entry at a time

    If key[Work subscript] < key[Subscript of smallest entry]

      Set Subscript of smallest entry to Work Subscript
    Endif
  Endfor

  Swap Table[TOP] and Table[Subscript of smallest entry]
Endfor

Internal Subroutine Requirements

Each of the routines listed above must have a storage area, which should include an area where the register contents can be saved upon entry to the routine (using STM), and restored before exiting (using LM).

When calling BUILD, PRINT or SORT, pass parameters to the routine by placing the address of a parameter list in register 1, as convention. The parameter list should be in the form of an address constant:

parmlist DC    A(parameter 1)
         DC    A(parameter 2)

Use register 11 as the return register from BUILD, PRINT and SORT.

Processing Requirements

  1. Use the following JCL statement to specify the input file:

  2. //FT05F001 DD DSN=KC02330.CSCI360.FILES(DATA5),DISP=SHR

  3. Use line documentation, documentation boxes, TITLE, EJECT, and SPACE as before. Don't forget that each subroutine MUST have its own documentation box.

  4. Use a multiple value of 1 to get the PRINT subroutine to display the contents of the entire table of numbers.

  5. Hand in a copy of your source code AND a listing of the Marist output on Blackboard.

Output

The output for the program should resemble the following:

The numbers - All
     -999999       -9090       -8426       -2005        -517        -419         -89
         -84         -80         -77          -1           0           1           3
           6           9          12          15          27          50          58
          62          89          90         111         114         118         121
         131         141         218         240         250         306         360
         402         464         515         516        5106        7534        9001
       14789       60205       95220      172219      204914      312909      606031


The numbers - Multiples of           6
       -9090         -84           0           6          12          90         114
         240         306         360         402         516        5106       95220


The numbers - Multiples of           3
     -999999       -9090         -84           0           3           6           9
          12          15          27          90         111         114         141
         240         306         360         402         516        5106       95220
      312909

The page header for each listing of numbers should start at the top of a new page. The lines with the numbers should be single spaced.