系列: haskell
haskell
41 行
· 更新於 2026-02-03
exercise08.hs
haskell/exercise08.hs
module GPACalculator
( Grade(..)
, Course(..)
, Mark
, markToGradeScaled
) where
-- From earlier exercises
data Grade = Fail | Pass | Credit | Distinction | HighDistinction
deriving (Show, Eq)
data Course = Art Int | Comp Int | Busn Int | Math Int
deriving (Show, Eq)
type Mark = Int
-- Helper: convert a numeric score (can be fractional after scaling) to a Grade
scoreToGrade :: Double -> Grade
scoreToGrade s
| s >= 80 = HighDistinction
| s >= 70 = Distinction
| s >= 60 = Credit
| s >= 50 = Pass
| otherwise = Fail
-- Scaling factor per course:
-- Busn 1000-level -> * 0.90
-- Other Busn -> * 0.95
-- All others -> * 1.00
scaleFactor :: Course -> Double
scaleFactor (Busn code)
| code >= 1000 && code < 2000 = 0.90
| otherwise = 0.95
scaleFactor _ = 1.00
-- && , and, || or
markToGradeScaled :: (Course, Mark) -> Grade
markToGradeScaled (c, m) =
let scaled = fromIntegral m * scaleFactor c -- keep as Double; no rounding needed
in scoreToGrade scaled
相關文章
haskell
haskell
更新於 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
閱讀文章 →