! PROGRAM P56 ! ! Program to process student grades and find top three ! IMPLICIT NONE INTEGER :: I,ID(500),Ass(500),Mid(500),Fin(500),Top_Index INTEGER :: J,NSTUD,N REAL :: Mark(500),Topmrk CHARACTER (LEN=25) :: Name(500) ! ! PRINT *, 'This is Program >> P56 - Class grades and top 3' ! ! Tell program where data for READ is coming from OPEN(UNIT=5, FILE='P56.DAT') ! UNIT=5 is the default input ! Print *,'ID Name Assign Mid Exam Total' Nstud = 0 READ *,N L1: Do I=1,N Read *, Id(i),Name(i),Ass(i),mid(i),fin(i) IF(ID(i) == 9999999) go to 100 Mark(i)=Ass(i)*.3 + Mid(i)*0.2 + Fin(i)*0.5 Nstud = Nstud + 1 Print 4,ID(i),Name(i),Ass(i),Mid(i),Fin(i),Mark(i) 4 Format(' ',I7,' ',A25,3I5,F7.1) End DO L1 Print *,'Too much data - Check IDs or increase array size' STOP ! 100 Print * ! A blank line Print *,'Top students are:-' L2: Do i=1,3 Top_Index=1 TopMrk = Mark(1) L3: Do J=2,Nstud If(Mark(j) > TopMrk) then Top_Index = j ! Pointer to Top slot TopMrk = Mark(j) End if End Do L3 Print 5,I,TopMrk,ID(Top_Index),Name(Top_Index) 5 Format(I3,F7.1,I9,' ',A25) Mark(Top_Index) = 0 ! Top only Once !! End Do L2 STOP END PROGRAM P56DATA:
12 9414154 'Opus' 74 81 71 9513986 'Bloom Milo' 91 75 85 9412978 'Dallas Steven' 74 71 69 9413693 'Cat Bill the' 86 49 73 9515010 'John Cutter' 73 41 64 9510633 'Jones Oliver' 69 85 63 9513221 'Mike Binkley' 58 47 84 9412526 'Snoopy' 48 75 94 9473522 'Charlie Brown' 81 65 72 9413986 'Linus Van Pelt' 91 81 96 9515010 'Woodstock' 61 41 54 9999999 'E-O-F Marker' 0 0 0OUTPUT:
+--------------------------------------------------+ | 32-bit Power for Lahey Computer Systems | | Phar Lap's 386|DOS-Extender(tm) Version 7.0 | | Copyright (C) 1986-94 Phar Lap Software, Inc. | | Available Memory = 14880 Kb | +--------------------------------------------------+ This is Program >> P56 - Class grades and top 3 ID Name Assign Mid Exam Total 9414154 Opus 74 81 71 73.9 9513986 Bloom Milo 91 75 85 84.8 9412978 Dallas Steven 74 71 69 70.9 9413693 Cat Bill the 86 49 73 72.1 9515010 John Cutter 73 41 64 62.1 9510633 Jones Oliver 69 85 63 69.2 9513221 Mike Binkley 58 47 84 68.8 9412526 Snoopy 48 75 94 76.4 9473522 Charlie Brown 81 65 72 73.3 9413986 Linus Van Pelt 91 81 96 91.5 9515010 Woodstock 61 41 54 53.5 Top students are:- 1 91.5 9413986 Linus Van Pelt 2 84.8 9513986 Bloom Milo 3 76.4 9412526 Snoopy
Last modified: 08/07/97