Internal Sorts
This is a program that uses internal sorts. The program should have three distinct modules:
You will need to include CALLs or comparable commands to execute external subroutines to do the actual sorts. The sorts should be done in separate modules and executed using the CALL statement.
You will need to set up two tables/arrays in your program to accumulate data - one for last years sales and one for this years sales. The tables/arrays should contain department number and accumulator slots to accumulate last years sales by department and this years sales by dept. The accumulator slots should start out as zero. You need to set up a table/array of department names (you make up the names - Im out of originality) to correspond to the department numbers.
On the printline you need to print the lines in order by last years sales. The lines should contain the department number, the department name, last years last years sales and this years sales along with a ranking of last years sales.
Module to gather the data:
Read the file named SORTDATA.DAT or a similiar file you create. The file I created is out on the Web site with the following layout:
1 - 2 |
Department Number |
3 - 8 |
Last Years Sales |
9 - 14 |
This Years Sales |
|
|
You will need to read the data file and add the sales to the appropriate accumulator slots in the tables/arrays (remember, each department has a slot in both the last years and this years table/array and you will add to the appropriate slot).
After you read all records, you will have in the table/array the total sales of last year by department and the total sales for this year by department.
Sort Module:
There will be two sort modules - one for last years data and one for this years data. You must use two different sorts - one to sort the this year array and one to sort the last year array. You cannot use the bubble sort since I have put out sample code for that. You can use the top down or another alogrithm that you find - I put sources out last week that I got by doing a search for bubble sort and then seeing what else was available at the site. Each of the sort modules should be done in a subprogram and called from you main program. The table/array data should be passed to the subprogram, sorted there, and the sorted data passed back to the main program. In sorting the tables/arrays, you want the highest value at the top of each table/array and the lowest sale at the bottom of each table/array. Hint: Be sure that you carry the department number with the accumulated totals so that you know which total goes with which department. When both tables/arrays are sorted, you have completed the Sort Module.
Print Module:
In this module you want to print the sorted data. You are going to print a line for each department. The lines will be in order by this years sales. On each line, print the department number, the department name, this years sales, last years sales, and a message column telling where the department ranked last year. In other words, if it is fourth in the table/array after the sort of the last year table/array, it ranked fourth last year and the word FORTH should be printed in the message area.
EXAMPLE:
(This does not use the sample data you are working with.)
Dept # |
Dept Name |
This Year Sales |
Last Year Sales |
Last Year Rank |
|
|
|
|
|
12 |
TOYS |
100,000 |
89,000 |
THIRD |
15 |
SPORTS |
75,000 |
93,000 |
FIRST |
17 |
GIFTS |
65,000 |
90,000 |
SECOND |
|
|
|
|
|