资源描述:
《fortran95程序设计习题答案第十章3》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、modulelinklisttypestudentinteger::numinteger::Chinese,English,Math,Science,Socialendtypetypedatalinktype(student)::itemtype(datalink),pointer::nextendtypecontainsfunctionSearchList(num,head)implicitnoneinteger::numtype(datalink),pointer::head,ptype(datalin
2、k),pointer::SearchListp=>headnullify(SearchList)dowhile(associated(p))if(p%item%num==num)thenSearchList=>preturnendifp=>p%nextenddoreturnendfunctionendmodulelinklistprogramex1016uselinklistimplicitnonecharacter(len=20)::filenamecharacter(len=80)::tempstrty
3、pe(datalink),pointer::headtype(datalink),pointer::ptype(student),allocatable::s(:)integeri,error,sizewrite(*,*)"filename:"read(*,*)filenameopen(10,file=filename,status="old",iostat=error)if(error/=0)thenwrite(*,*)"Openfilefail!"stopendifallocate(head)nulli
4、fy(head%next)p=>headsize=0read(10,"(A80)")tempstr!读入第一行字符串,不需要处理它!读入每一位学生的成绩dowhile(.true.)read(10,fmt=*,iostat=error)p%itemif(error/=0)exitsize=size+1allocate(p%next,stat=error)!新增下一个数据if(error/=0)thenwrite(*,*)"Outofmemory!"stopendifp=>p%next!移动到链表的下一个数据
5、nullify(p%next)enddowrite(*,"('总共有',I3,'位学生')")sizeallocate(s(size))p=>headdoi=1,sizes(i)=p%itemp=>p%nextenddodowhile(.true.)write(*,*)"要查询几号同学的成绩?"read(*,*)iif(i<1.or.i>size)exit!输入不合理的座号write(*,"(5(A6,I3))")"中文",s(i)%Chinese,&"英文",s(i)%English,&"数学",s(i)
6、%Math,&"自然",s(i)%Science,&"社会",s(i)%Socialenddowrite(*,"('座号',I3,'不存在,程序结束.')")istopendprogram