![]() |
Department of
Mathematics and Computer Science |
|
Math 60 -- Winter, 2006
|
|
35 points DUE: NOON: Friday, February 17, 2006 |
I assume you will create a new subdirectory for this program, as I suggested with the first program, and also create a new makefile.
In file mp4in.inp in my Math 60 directory on math, there is a list of the "inmates" of 5th floor Dunne for 1986-87 (including yours truly). You can copy this file to your desired directory by typing the following command (in bold):
math 34: cp /home/dsmolars/ma60/mp4in.inp .
Note: Don't omit the final period after a space!
(The file is also available on
the web by clicking on the link above.)
As given in this file, this list is not in any particular order. Each name is followed by a room number. All names are given last name first, and the names are at most 30 characters long. The very first item in the file is an integer giving the total number of individuals in the list. There are no more than 100 name-room combinations in the file.
Ideally, you would experiment with allocatable arrays and allocate an array of the proper dimension after you read the very first item in the file. If this seems too difficult, however, you can declare an array of large enough size and only use part of it in the sorting routines.
In this programming assignment you are to sort the list twice, first by room number and a second time alphabetically.
You must remember to keep the right room number associated with the right name throughout the two sorting processes. To do this, you must use Fortran-90/95 derived types. You should put the definition of the derived type in a module and make use of this module in all subprograms that need it.
Your program should print out two different listings: (1) one by room number (in order), with the room number first, and (2) the other alphabetical with name first on each line. Each list should include both name and room number (but in different orders), as well as an initial sequential number (starting at 1) before the other information on each line (for reference purposes).
Turn in the program and output, but not the input file.
SUGGESTIONS AND COMMENTS:
In your first sorting routine (e.g., sortint), if you use bubblesort your comparison test should look like:
if(student[index+1]%room < student[index]%room) then
Call Switch(student[index],student[index+1])
Thus, in your second sorting routine (e.g., sortchar),
if you use bubblesort your comparison test should look like:
if(llt(student[index+1]%name,student[index]%name)) then Call Switch(student[index],student[index+1])(These comparison tests presuppose bubblesort rather than selection sort -- if you use selectionsort, you must make the appropriate adaptations.)
mp4 < mp4in.inp > mp4ou.out
to have the program read from input file mp4in.inp and
write to mp4ou.out.
Turn in the source file (i.e., the program code
file) and the output file.
This can be done by using the Unix command
enscript mp4.f90 mp4ou.out
(assuming these are your actual filenames). You can also use
the procedure as in MP 1 to create PostScript (PS) files first
and then use the lp command to print out the PS files.
As with the previous programs, your sheets may be turned in to my office, O'Connor 32, or to my mailbox in O'Connor 31. Please staple the pages yourself and do not turn in disconnected pages!