! bank.f90 ! ! BANK ACCOUNT PROGRAM: ! TRANSACTIONS "OPEN" "CLOSE" "DEPOSIT" "WITHDRAW" ! ACCOUNT_NAME, TRANSACTION , AMOUNT ! ! 11/5/96 JSS modified from previous course program bank implicit none character (len=10), dimension(50) :: ACCOUNT_NAMES real, dimension(50) :: BALANCES character (len=10) :: ACCOUNT_NAME character (len=8) :: TRANSACTION real :: AMOUNT integer :: OPEN_ACCOUNTS = 0 integer :: INDEX integer :: iostat do print *, " ENTER TRANSACTION. name(10) transaction(8) amount " read(5,fmt="(a10, 1x, a8, 1x, f5.2)",iostat=iostat) & ACCOUNT_NAME, TRANSACTION, AMOUNT if (iostat > 0) then print *, " BAD DATA IGNORED " cycle end if if (iostat < 0) exit ! normal exit of loop upon end of file ! *********** put more tests for bad data here ************* write(6,fmt="(a10, 1x, a8, 1x, f7.2)") & ACCOUNT_NAME, TRANSACTION, AMOUNT INDEX = FIND_ACCOUNT(ACCOUNT_NAME) ! uses internal function above if (TRANSACTION == "OPEN ") then print *, " OPEN " ! debug print if (INDEX /= 0) then print *, " ACCOUNT ALREADY OPEN " else OPEN_ACCOUNTS = OPEN_ACCOUNTS + 1 ACCOUNT_NAMES(OPEN_ACCOUNTS) = ACCOUNT_NAME BALANCES(OPEN_ACCOUNTS) = AMOUNT end if else if (TRANSACTION == "CLOSE ") then print *, " CLOSE " ! debug print ! *********** missing code ************** else if (TRANSACTION == "DEPOSIT ") then print *, " DEPOSIT " ! debug print ! *********** missing code ************** else if (TRANSACTION == "WITHDRAW") then print *, " WITHDRAW " ! debug print ! *********** missing code ************** end if end do print *, " END OF INPUT DATA, OPEN_ACCOUNTS = ", OPEN_ACCOUNTS call PRINT_ACCOUNTS ! calls internal subroutine ! problem 7 stuff on next two lines ! call HeapSort(ACCOUNTS(1:OPEN_ACCOUNTS), BALANCES(1:OPEN_ACCOUNTS)) ! call PRINT_ACCOUNTS print *, " BANK IS CLOSED." contains ! internal function that finds index of account name if ! presently open, else returns zero for no find. function FIND_ACCOUNT(NAME) result(I) character (len=10), intent(in) :: NAME integer :: I do I=1,OPEN_ACCOUNTS if (NAME == ACCOUNT_NAMES(I)) then return end if end do I = 0 end function FIND_ACCOUNT ! internal subroutine with no arguments to print the ! status of accounts still open at end of run. subroutine PRINT_ACCOUNTS ! *********** missing code goes here *********** end subroutine PRINT_ACCOUNTS end program BANK