! ----- Module ListType ----------- Module ListType ! Make a Basic Module Implicit None Integer, Parameter :: number=200 Integer :: i,j,total Type StdType ! ÆÄ»ýÇü Type »ý¼º Character(len=14) :: no Character(len=10) :: name Character(len=13) :: tel Character(len=40) :: address End Type StdType Type(StdType), Dimension(number) :: a ! StdTypeÀÎ Type ÀÌ¿ë End Module ListType ! ----- Main Program Address Table ----------- Program AddTable Implicit None Character(len=1) :: ans Call Viewlist 10 Print *, "What do you want to " Print *, " Add [a], Change [c], View [v], Quit [q] a list. " Read *, ans If (ans=='a') Then Call Addlist ! Add a list to list.dat Elseif (ans=='c') Then Call Changelist ! Change a list Elseif (ans=='v') Then Call Viewlist Else ; Stop EndIf Go to 10 End Program AddTable ! ----- Subrouting Change List ----------- Subroutine Changelist Use ListType Integer :: who Character(len=40) tmp Print *, "Which number do you want to change ? " Read *, who Print *, ' ¹øÈ£ ÇÐ ¹ø ¼º ¸í ÀüÈ­¹øÈ£ Email ÁÖ¼Ò ' Write(*,21) who,a(who) Print *, 'Current ID Number = ',a(who)%no,' No change [n]' ! n => don't change Read(*,"(A14)") tmp If (tmp/='n') a(who)%no=tmp(1:14) Print *, 'Current Name = ',a(who)%name,' No change [n]' Read(*,"(A10)") tmp If (tmp/='n') a(who)%name=tmp(1:10) Print *, 'Current Telephone = ',a(who)%tel,' No change [n]' Read(*,"(A13)") tmp If (tmp/='n') a(who)%tel=tmp(1:13) Print *, 'Current Email = ',a(who)%address,' No change [n]' Read(*,"(A40)") tmp If (tmp/='n') a(who)%address=tmp Write(*,21) who,a(who) Open(1,File='list.dat') Write(1,"(I4)") total ! Add the total number to the first line of "list.dat" Do i=1,total Write(1,21) i,a(i) ! Write the total list from the second line of "list.dat" EndDo 21 Format(I4,4x,A14,4x,A10,4x,A13,4x,A40) Close(1) End Subroutine Changelist ! ----- Subrouting Add List ----------- Subroutine Addlist Use ListType Open(1,File='list.dat') Write(1,"(I4)") total+1 Do i=1,total Write(1,21) i,a(i) EndDo i=total+1 Print *, 'Student Number ?' Read(*,"(A14)") a(i)%no Print *, 'Name ? ' Read(*,"(A10)") a(i)%name Print *, 'Telephon Nmumber ? ' Read(*,"(A13)") a(i)%tel Print *, 'Email Address ? ' Read(*,"(A40)") a(i)%address Write(1,21) i,a(i) 21 Format(I4,4x,A14,4x,A10,4x,A13,4x,A40) Close(1) End Subroutine Addlist ! ----- Subrouting View List ----------- Subroutine Viewlist Use ListType Open(1,File='list.dat') Read(1,"(I4)") total Print *, "-------------------------------------------------------------------------" Print *, ' ¹øÈ£ ÇÐ ¹ø ¼º ¸í ÀüÈ­¹øÈ£ Email ÁÖ¼Ò ' Print *, "-------------------------------------------------------------------------" Do i=1,total Read(1,21) i,a(i) Write(*,21) i,a(i) EndDo Print *, "-------------------------------------------------------------------------" Close(1) 21 Format(I4,4x,A14,4x,A10,4x,A13,4x,A40) End Subroutine Viewlist