! ! =====> Program - P56.F90 ! ! Program to process student grades and find top three ! Integer ID(500),Ass(500),Mid(500),Fin(500),Top_Index 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 L1: Do I=1,500 Read 3, Id(i),Name(i),Ass(i),mid(i),fin(i) 3 Format(I7,3x,A25,5x,3I5) 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(1x,I7,2x,A20,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) Endif End Do L3 Print 5,I,TopMrk,ID(Top_Index),Name(Top_Index) 5 Format(I3,F7.1,I9,2x,A25) Mark(Top_Index) = 0 ! Top only Once !! End Do L2 END DATA: 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
Page builder: Charles Boivin
Last modified: 11/07/95