Untitled

 avatar
unknown
plain_text
a year ago
1.8 kB
2
Indexable
type Aluno = (Numero,Nome,Regime,Classificacao)
type Numero = Int
type Nome = String
data Regime = ORD | TE | MEL deriving Show
data Classificacao = Aprov Int
                   | Rep
                   | Faltou
                deriving Show
type Turma = BTree Aluno -- ´arvore binária de procura (ordenada por número)

arvT :: BTree Aluno
arvT = Node aluno3                                          
           (Node aluno2 (Node aluno1 Empty Empty)                           
                        Empty)                                
           (Node aluno4 Empty Empty)

aluno1 :: Aluno
aluno1 = (1, "Concha", ORD , Aprov 20)
aluno2 :: Aluno
aluno2 = (5, "Jose", TE, Rep)
aluno3 :: Aluno
aluno3 = (9, "Rui", TE, Faltou)
aluno4 :: Aluno
aluno4 = (11, "Toze", MEL, Aprov 10)

--a) 
inscNum :: Numero -> Turma -> Bool
inscNum x Empty = False
inscNum x (Node aluno l r) | numAluno == x = True
                           | numAluno  < x = inscNum x r
                           | numAluno  > x = inscNum x l
            where (numAluno, _, _, _) = aluno

--b)
inscNome :: Nome -> Turma -> Bool
inscNome n Empty = False
inscNome n (Node aluno l r) | nomeAluno == n = True
                            | nomeAluno  < n = inscNome n r
                            | nomeAluno  > n = inscNome n l
            where (_, nomeAluno, _, _) = aluno

--c) não ordenado por nº
trabEst :: Turma -> [(Numero,Nome)]
trabEst Empty = []
trabEst (Node aluno l r) =
    case aluno of
        (numero, nome, TE, _) -> (numero, nome) : trabEst l ++ trabEst r
        _                     -> trabEst l ++ trabEst r              

--d)
nota :: Numero -> Turma -> Maybe Classificacao
nota x Empty = Nothing
nota x (Node aluno l r)
    | inscNum x (Node aluno l r) == False = Nothing
    | otherwise = Just clas
        where (x, nome, reg, clas) = aluno
Editor is loading...