Advertisement
azwan

Tutorial 5 Fortran

May 4th, 2011
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PROGRAM tut5
  2. ! Program that computes the bonus paid to several employees given their annual sales
  3.  
  4. IMPLICIT NONE
  5. REAL :: Sum, average
  6. INTEGER :: EmployeeNo
  7. INTEGER, PARAMETER :: EmployeeTotal = 11
  8. INTEGER, DIMENSION ( EmployeeTotal ) :: identity, sales, BonusPercent  
  9. REAL, DIMENSION ( EmployeeTotal ) :: paid
  10.  
  11. OPEN ( 10, FILE = "input.txt" )
  12. OPEN ( 30, FILE = "output.txt" )
  13.  
  14. EmployeeNo = 1
  15.  
  16. DO
  17.     READ ( 10, * ) identity ( EmployeeNo ), sales ( EmployeeNo )
  18.     IF ( EmployeeNo == EmployeeTotal ) EXIT
  19.     EmployeeNo = EmployeeNo + 1
  20. END DO
  21.  
  22. WRITE ( 30, '(1x, a68)' ) "YEARLY BONUS REPORT FOR MUHIBBAH ENGINEERING"
  23. WRITE ( 30, '(1x, a68, /)' ) "--------------------------------------------"
  24. WRITE ( 30, '(1x, a15, a21, a21, a15)' ) "Salesperson ID", "Yearly Sales", "Bonus Percentage", "Bonus Paid"
  25. WRITE ( 30, '(1x, a15, a21, a21, a15)' ) "--------------", "------------", "----------------", "----------"
  26. WRITE ( 30, '(1x, a30, a17, a20, /)' ) "(RM)", "(%)", "(RM)"
  27.  
  28. PRINT '(1x, a68)', "YEARLY BONUS REPORT FOR MUHIBBAH ENGINEERING"
  29. PRINT '(1x, a68, /)', "--------------------------------------------"
  30. PRINT '(1x, a15, a21, a21, a15)', "Salesperson ID", "Yearly Sales", "Bonus Percentage", "Bonus Paid"
  31. PRINT '(1x, a15, a21, a21, a15)', "--------------", "------------", "----------------", "----------"
  32. PRINT '(1x, a30, a17, a20, /)', "(RM)", "(%)", "(RM)"
  33.  
  34. CALL BonusSchedule ( EmployeeTotal, sales, BonusPercent, paid )
  35.  
  36. EmployeeNo = 1
  37. Sum = 0.0
  38.  
  39. DO 
  40.     WRITE ( 30, '(1x, i10, i22, i15.2, f23.2)' ) identity ( EmployeeNo ), sales ( EmployeeNo ), &
  41.         BonusPercent ( EmployeeNo ), paid ( EmployeeNo )
  42.  
  43.     PRINT '(1x, i10, i22, i15.2, f23.2)', identity ( EmployeeNo ), sales ( EmployeeNo ), &
  44.         BonusPercent ( EmployeeNo ), paid ( EmployeeNo )
  45.    
  46.     Sum = Sum + sales ( EmployeeNo )
  47.    
  48.     IF ( EmployeeNo == EmployeeTotal ) EXIT
  49.     EmployeeNo = EmployeeNo + 1
  50. END DO
  51.  
  52. average = Sum / EmployeeTotal
  53.  
  54. WRITE ( 30, *)
  55. WRITE ( 30, '(1x, a25, f10.2, /)' ) "average yearly sales = RM", average
  56. PRINT *
  57. PRINT '(1x, a25, f10.2, /)', "average yearly sales = RM", average
  58.  
  59. CONTAINS
  60.  
  61. SUBROUTINE  BonusSchedule ( total, Sales, Percent, paid )
  62. INTEGER :: I, Start = 1
  63. INTEGER, INTENT ( IN ) :: total
  64. INTEGER, DIMENSION ( total ), INTENT ( IN ) :: Sales
  65. INTEGER, DIMENSION ( total ), INTENT ( OUT ) :: Percent
  66. REAL, DIMENSION ( total ), INTENT ( OUT ) :: paid
  67.  
  68. DO I = Start, total
  69.     IF ( Sales ( I ) < 20000 ) THEN
  70.         Percent ( I ) = 0
  71.     ELSE IF ( Sales ( I ) < 100000 ) THEN
  72.         Percent ( I ) = 2
  73.     ELSE IF ( Sales ( I ) <= 200000 ) THEN
  74.         Percent ( I ) = 3
  75.     ELSE
  76.         Percent ( I ) = 5
  77.     END IF
  78.     paid ( I ) = Percent ( I ) * Sales ( I ) / 100.0
  79. END DO
  80. END SUBROUTINE BonusSchedule
  81. END PROGRAM tut5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement