小新 发表于 2018-5-31 18:10:54

学生成绩处理做一半求助

录入一个班的学生的学号,平时成绩,期末成绩,按照平时成绩×0.3+期末成绩*0.7=总评成绩,计算总评成绩,并统计出各个分数段的人数,并对成绩进行排名

type chengji
   integer::xuehao
   real::pingshichengji
   real::qimochengji
   real::zongpingchengji
end type
type(chengji) xueshengchengji(n)
print*,"请输入学生人数"
read*,n
print*,"请输入"n"名学生的学号、平时成绩、期末成绩"
print*,"数据之间用空格间隔、学号为长度为12的字符串、用引号括住"
do i=1,n
read*,number(i),pingshichengji(i),qimochengji(i)
zongpingchengji(i)=0.3*pingshichengji(i)+0.7*qimochengji(i)
print*,zongpingchengji(i)
dimension m(11),s(n)!将成绩分为11个分数段0-9、10-19以此类推,一直到100
data m/11 *0/
read(*,*)(s(i),i=1,n)
do i=1,n
   if(s(i))<=100.and.s(i)>=0)then
   k=s(i)/10+1
         m(k)=m(k)+1
   end if
end do
write(*,*)m非专业所需,所以学的很浅,后悔了,求助各位大神!急!


小新 发表于 2018-5-31 18:19:00

FORTRAN 95

Jackdaw 发表于 2018-5-31 18:35:45

program main
implicit none
type chengji
    integer::s_id
    real::pscj
    real::qmcj
    real::zcj
end type

integer :: i
type(chengji),allocatable :: student(:)

write(*,*) "请输入学生人数"
read(*,*) n
allocate( student(n) )

write(*,*) "请输入",n,"名学生的学号、平时成绩、期末成绩"
do i =1,n
    read(*,*) student(i)%sid,student(i)%pscj,student(i)%qmcj
end do
do i =1,n
    student(i)%zcj = 0.3*student(i)%pscj+0.7*student(i)%qmcj
end do
! 然后,排序,统计
end

渡箭 发表于 2018-5-31 18:42:54

楼上说的很好!

小新 发表于 2018-5-31 18:48:14

Jackdaw 发表于 2018-5-31 18:35
program main
implicit none
type chengji


大哥,不会排序啊

fcode 发表于 2018-5-31 19:05:25

这是我们以前的作业,供你参考

Module StudMod
Implicit None
Integer , Parameter :: INUMBER_OF_COURSE = 6
Type T_Stud
    Integer :: iStuNumber !//学号
    Real :: rScore( INUMBER_OF_COURSE ) !//6门成绩
    Real :: rScoreAll , rScoreAvg !//总分和平均分
End Type T_Stud

Contains

Subroutine GetStudInfo( cFilename , stStudArray )
    Character( Len = * ) ,Intent( IN ) :: cFilename
    Type( T_Stud ) , Intent( OUT ) :: stStudArray( : )
    Integer :: i
    Open( 12 , File = cFilename )
    Do i = 1 , size( stStudArray )
      Read( 12 , * ) stStudArray( i )%iStuNumber , stStudArray(i)%rScore
    End Do
    Close( 12 )
End Subroutine GetStudInfo

Subroutine CalcScore( stStud )
    Type( T_Stud ) , Intent( INOUT ) :: stStud
    Integer :: i
    Real :: rTmp
    rTmp = 0.0
    Do i = 1 , INUMBER_OF_COURSE
      rTmp = rTmp + stStud%rScore( i )
    End Do
    stStud%rScoreAll = rTmp
    stStud%rScoreAvg = rTmp / INUMBER_OF_COURSE
End Subroutine CalcScore

Subroutine OutputInfo( stStud , iNum )
    Type( T_Stud ) , Intent( IN ) :: stStud(:)
    Integer , Intent( IN ) :: iNum
    Write(*,"(i,6f7.1,f9.1,f9.3)") stStud( iNum )%iStuNumber,stStud( iNum )%rScore ,stStud( iNum )%rScoreAll, stStud( iNum )%rScoreAvg
End Subroutine OutputInfo

Subroutine HeapSort( stD , comp_f )
    Type ( T_Stud ) , Intent( INOUT ) :: stD( : )
    Real , External :: comp_f
    Integer i,ir,j,l,n
    Type ( T_Stud ) :: stTemp
    n = size( stD )
    If ( n < 2 ) Return
    l = n / 2 + 1
    ir = n
    Do while( .TRUE. )
      If( l > 1 ) then
      l = l - 1
      stTemp = stD( l )
      Else
      stTemp = stD( ir )
      stD( ir ) = stD( 1 )
      ir = ir - 1
      If( ir == 1 ) then
          stD( 1 ) = stTemp
          return
      End If
      End If
      i = l
      j = l + l
      Do while( j<=ir )
      If( ( j < ir ) ) then
          If ( comp_f( stD(j) , std(j+1) ) > 0.0 ) then
            j = j+1
          End If
      EndIf
      If( comp_f( stTemp , stD(j) ) > 0.0 )then
          stD(i) = stD( j )
          i = j
          j = j + j
      Else
          j = ir + 1
      End If
      EndDo
      stD( i ) = stTemp
    End Do
End Subroutine HeapSort

Real Function comp_f_Score( st1 , st2 )
    Type( T_Stud ) , Intent( IN ) :: st1 , st2
    comp_f_Score = st1%rScoreAll - st2%rScoreAll
End Function comp_f_Score



End Module StudMod



Program Main
Use StudMod
Implicit None
Integer , Parameter :: INUMBER_OF_STUD = 35 !35个学生
Type( T_Stud ) :: stStuds( INUMBER_OF_STUD ) !定义学生数组结构体
Integer :: i , iCourseNumber
Call GetStudInfo( "info.dat" , stStuds ) !读入学生信息
Do i = 1 , INUMBER_OF_STUD
    Call CalcScore( stStuds(i) ) !计算平均分和总分
End Do
Call HeapSort( stStuds , comp_f_Score ) !排序
Do i = 1 , INUMBER_OF_STUD
    Call OutputInfo( stStuds , i ) !输出排序后的学生信息
End Do
Write(*,*) "请输入挑选的课程号(1-6):"
Read(*,*) iCourseNumber
Do i = 1 , 5
    If( stStuds(i)%rScore( iCourseNumber ) > 90.0 ) then
      Call OutputInfo( stStuds , i ) !输出满足筛选条件的学生信息
    End If
End Do
End Program Main

Yowai 发表于 2018-5-31 19:17:20

您好,请参考 彭国伦 教材,第149页。

Jackdaw 发表于 2018-6-1 00:18:53

小新 发表于 2018-5-31 18:48
大哥,不会排序啊

除了说不会以外,会不会学?
页: [1]
查看完整版本: 学生成绩处理做一半求助