Lista 01 - Recursão Completa
Autor: Beatriz | Publicado: 2013-10-09T06:15:00-07:00

-- Bons estudos à TODOS&nbsp; 
-- Lista de Exercicio 01

vendas :: Int -&gt; Int
vendas 1 = 20
vendas 2 = 32
vendas 3 = 21
vendas 4 = 60
vendas 5 = 25
vendas 6 = 12
vendas 7 = 52
vendas 8 = 28
vendas 9 = 29
vendas 10 = 40
vendas 11 = 50
vendas 12 = 33

-- Questao 01

desloca :: Int -&gt; String -&gt; String
desloca d palavra
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | d == 0 = palavra
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | d &gt; 0 =&nbsp; " " ++ desloca (d - 1) palavra

-- Questao 02

impAsterisco :: Int -&gt; String
impAsterisco&nbsp; qtd
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | qtd == 0 = ""
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | qtd &gt; 0 = "*" ++ impAsterisco (qtd - 1) 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
-- Questao 03

centraliza:: String -&gt; String
centraliza palavra = desloca (length (palavra)) palavra ++ desloca (length (palavra)) ""

-- Questao 04

tamanhoLinha :: Int
tamanhoLinha = 40

cabecalho :: String 
titulo = "Relatorio de Venda de Microcomputadores"
cabecalho = impAsterisco tamanhoLinha ++ centraliza titulo ++ impAsterisco (tamanhoLinha +1) ++ "\n"

-- Questao 05

mes :: Int -&gt; String
mes m
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 00 = "Este mes nao existe."
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 01 = "Janeiro"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 02 = "Fevereiro"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 03 = "Marco"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 04 = "Abril"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 05 = "Maio"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 06 = "Junho"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 07 = "Julho"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 08 = "Agosto"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 09 = "Setembro"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 10 = "Outubro"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 11 = "Novembro"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | m == 12 = "Dezembro"
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
-- Questao 06

impBranco :: Int -&gt; String
impBranco&nbsp; qtd
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | qtd == 0 = ""
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | qtd &gt; 0 = " " ++ impBranco (qtd - 1)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
-- Questao 07

impMes :: Int -&gt; String
impMes mesp = desloca 6 (mes mesp) ++ impBranco (tamanhoLinha - length(mes mesp)) ++ show (vendas mesp) ++ "\n"

-- Questao 08

impMeses :: Int -&gt; String
impMeses 1 = impMes 1 ++ "\n"
impMeses messp = impMeses (messp - 1) ++ impMes messp ++&nbsp; "\n"&nbsp;&nbsp; 

-- Questao 09

somaVendas :: Int -&gt; Int
somaVendas 1 = vendas 1
somaVendas v = somaVendas (v - 1) +&nbsp; vendas v

-- Questao 10

impSoma :: Int -&gt; String
impSoma sv = impAsterisco tamanhoLinha ++ "\n" ++ desloca 6 ("Total de Vendas: ") ++ show (somaVendas sv) ++ "\n"

-- Questao 11

maiorVenda :: Int -&gt; Int 
maiorVenda 1 = vendas 1
maiorVenda maior = maiorVendaAux (vendas maior) (maiorVenda (maior - 1)) 

maiorVendaAux :: Int&nbsp; -&gt; Int -&gt; Int
maiorVendaAux v1 v2
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | v1 &gt;= v2 = v1
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | otherwise = v2

-- Questao 12
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
impMaior :: Int -&gt; String
impMaior mv = desloca 5 (" Maior Venda no Periodo: ") ++ show (maiorVenda mv)&nbsp;&nbsp;&nbsp; 

impVendaZerada :: Int -&gt; String
impVendaZerada vz = desloca 6 ("Vendas Zeradas: ") ++ show (vendasZeradas vz) ++ "\n"

vendasZeradas :: Int -&gt; Int
vendasZeradas 0 = 0
vendasZeradas vmes =&nbsp; testa0 (vmes) + vendasZeradas (vmes - 1) 

testa0 :: Int -&gt; Int
testa0&nbsp; vmz 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | vendas vmz == 0 = 1
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | otherwise = 0

-- Questao 13

geraGraf :: Int -&gt; String
geraGraf 1 = "\n" ++ desloca 6 ("Grafico de Vendas: ") ++ "\n"&nbsp; ++ "\t" ++ impAsterisco (vendas 1) ++ "\n"
geraGraf astGraf = geraGraf (astGraf - 1) ++ "\t" ++ impAsterisco (vendas astGraf) ++ "\n"

-- Questao 14

relatorio :: Int -&gt; IO( )
relatorio n = putStr (cabecalho ++ impMeses n ++ 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; impSoma n ++ impVendaZerada n ++&nbsp; impMaior n ++ geraGraf n)