Fortran 90 Coding Help


Recommended Posts

This programming exercise involves writing software to help with the task of

timetabling courses for a fictitious university. The mathematics department at

UWGC offers 24 modules with codes A1..A8; B1..B8 and C1..C8. It has five

classrooms for its exclusive use: rooms 1 and 2 have 20 seats, room 3 has 30 and

rooms 4 and 5 can each take 50 students. Classes can be scheduled to begin on

the hour from 9.00 till 16.00 each day of the week (except Wednesday when the

last class is at 12.00).

The timetabler needs software to perform the following tasks:

• to print the current state of the timetable

• to answer a query about the usage of a given slot (i.e. room, day and time)

• to list which rooms are free at a given day and time

• to list the timetabled hours for any given course

• to allow the current state of the timetable to be changed by adding a module

code in a free timetable slot and/or deleting a course from an existing slot

When adding a module code in a slot, the software must check that the slot is actually

free and also make some tests on room size and possible timetable clashes.

(i) All ’A’ classes have 25 students

(ii) Classes B1..B6 have 15 students while B7 and B8 have 35

(iii) All ’C’ classes have at most 10 students

(iv) Courses B7 and B8 cannot run simultaneously

If the timetabler attempts to schedule a class which violates one or more of these

rules, the software should not accept it and print a warning message instead.

The software is to be menu-driven – that is, it should offer choices

Display a timetable (1)

Check a timetable slot (2)

Check free rooms at a given day and time (3)

Check timetabled slots for a given course (4)

Release a slot (5)

Allocate a slot (6)

Your solution must be implemented in terms of two-dimensional arrays. That is the variable mon (i,j)

should hold the module code of the class to be held on a Monday in room i( 1 < i < 5) at time j(9<j<16)

(If no class is scheduled then mon(i,j) could have a default value such as ’--’.)

Your solution must use function subprograms and/or subroutines – i.e., it is not to

consist of a single main program. For instance, the tests on room size ((i) - (iii),

The code must include comments which help a user understand

how to work with the software. In addition to your code you must hand in sample

output listings which show that you have tested all the features of the program.

It is advisable to build your software solution in stages – that is, to write and test

the program and subprograms for displaying the current timetable; then to add

(and test) further code for checking usage of a particular slot; and so on for all

menu options.

My current coding

FUNCTION room_ok(K, M)

INTEGER :: K ! room number

CHARACTER(LEN=2) :: M ! module code

LOGICAL :: room_ok

! room_ok is returned as T if the number of seats in room K

! does not exceed the number of students on module M

! Otherwise it is returned as F

PROGRAM timetable

IMPLICIT NONE

CHARACTER(LEN=2), DIMENSION(1:5,9:16) :: mon, tue, wed, thu, fri

INTEGER, DIMENSION(1:5) :: roomsize

CHARACTER(LEN=2) :: mc

CHARACTER(LEN=3) :: day

INTEGER :: choice, room, hour

! Initialise room data

roomsize(1) = 20; roomsize(2) = 20; roomsize(3) = 30

roomsize(4) = 50; roomsize(5) = 50

! Initialise empty timetable

mon = ’--’; tue = ’--’; wed = ’--’; thu = ’--’; fri = ’--’

! non-trivial entries for testing

mon(2,10) = ’A4’; tue(3,12) = ’A4’; wed(4,16) = ’B6’

DO

CALL Menu

READ*,choice

SELECT CASE (choice)

CASE (1) ! Prints timetable for one day

PRINT"(’Which day (Mon - Fri)?’)": READ*,day

CALL Print_day(day)

...

CONTAINS

SUBROUTINE Menu ! prints option choices

PRINT"(/,’**** UWGC Timetable wizard ****’)"

PRINT"(’OPTIONS:’)"

PRINT"(’Display a timetable (1)’)"

PRINT"(’Check a timetable slot (2)’)"

PRINT"(’Check free rooms at a given day and time (3)’)"

PRINT"(’Check timetabled slots for a given course (4)’)"

PRINT"(’Release a slot (5)’)"

PRINT"(’Allocate a slot (6)’)"

END SUBROUTINE Menu

SUBROUTINE Print_day(day) ! Prints timetable for day specified

CHARACTER(LEN=3), INTENT(in) :: day

SELECT CASE(day)

CASE(’Mon’)

CALL Print_times(mon)

CASE(’Tue’)

CALL Print_times(tue)

CASE(’Wed’)

CALL Print_times(wed)

CASE(’Thu’)

CALL Print_times(thu)

CASE(’Fri’)

CALL Print_times(fri)

CASE default

PRINT"(’Invalid day!’)"

END SELECT

END SUBROUTINE Print_day

Any help with the rest of the coding is appreciated, having difficulty from this point on.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...