Program student_records !------------------------------------------------------------------------------ !Program: Student Record GPA Calculator with File I/O !Author: Chris Harper !Date: 2/17/2008 !------------------------------------------------------------------------------ IMPLICIT NONE !declarations integer :: ERR, EOF, stuID, hours(4) real :: grade(4), gpa, points(4) character (20) :: name !open files open(unit = 10, file = "students.dat", status = "old", iostat = ERR) open(unit = 11, file = "students_gpa.dat", status = "unknown") !if no error if (ERR == 0) then !for all lines in the input file do !read the formatted line !grades and hours go into an array read (10, "(I9, 1X, A20, 4(1X, I1, 1X, F3.1))", iostat = EOF), & stuID, name, hours(1), grade(1), hours(2), grade(2), hours(3), grade(3), & hours(4), grade(4) if (EOF < 0) then !if EOF, exit loop exit else if (EOF > 0) then !if error, print a message and exit print *, "File read error occured. Error Number: ", EOF exit endif !calculate gpa using array functions points = hours * grade gpa = sum(points) / sum(hours) !output formatted line write(11, "(I9, '|', A20, 4('|', I1, '|', F3.1), '|', F4.2)"), & stuID, name, hours(1), grade(1), hours(2), grade(2), hours(3), grade(3), & hours(4), grade(4), gpa enddo else print *, "File open error occured. Error Number: ", ERR endif close(10) close(11) end