Advertisement
cardel

FDP Ejercicio 31 de Julio

Jul 31st, 2020
2,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.91 KB | None | 0 0
  1. ;.
  2.  
  3.  
  4. (define-struct salario-senador (salBase gastRep primSer))
  5. (define-struct salario-representante (salBase gasolin gastRep primSer))
  6. (define-struct salario (total retefuente devengado))
  7.  
  8. (define emperorPetrosky (make-salario-senador 45000000  300000 8000000))
  9. (define estebanQuito
  10.    (make-salario-representante
  11.              30000000
  12.                 3000000
  13.               20000000
  14.                 5000000))
  15.  
  16.  
  17. ;;Autor: Carlos A Delgado
  18. ;;Fecha 31 de Julio de 2020
  19. ;;Contrato: calcular-salario: congresista -> salario
  20. ;; Ejemplos
  21. ;; (calcular-salario emperorPetrosky)  (make-salario 53300000 6396000 46904000)
  22. ;; (calcular-salario estebanQuito) (make-salario 58000000 6960000 51040000)
  23. (define (calcular-salario cong)
  24.   (cond
  25.     [(salario-senador? cong)  
  26.      (make-salario
  27.       ;;Salario total
  28.       (calcular-total-senador cong)
  29.       ;;Retefuente
  30.       (* 0.12 (calcular-total-senador cong))
  31.       ;;Devengado
  32.       (* 0.88 (calcular-total-senador cong))
  33.       )]
  34.     [(salario-representante? cong)
  35.      (make-salario
  36.       ;;Salario total
  37.       (calcular-total-representante cong)
  38.       ;;Retefuente
  39.       (* 0.12 (calcular-total-representante cong))
  40.       ;;Devengado
  41.       (* 0.88 (calcular-total-representante cong))
  42.       )]
  43.                                  
  44.     [else (error "La estructura cong debe ser senador o representante")]))
  45.  
  46. (define (calcular-total-senador cong)
  47.   (+ (salario-senador-salBase cong)
  48.      (salario-senador-gastRep cong)
  49.      (salario-senador-primSer cong)
  50.      ))
  51.  
  52. (define (calcular-total-representante cong)
  53.   (+ (salario-representante-salBase cong)
  54.      (salario-representante-gasolin cong)
  55.      (salario-representante-gastRep cong)
  56.      (salario-representante-primSer cong)
  57. ))
  58.  
  59. (check-expect (calcular-salario emperorPetrosky)  (make-salario 53300000 6396000 46904000))
  60. (check-expect (calcular-salario estebanQuito) (make-salario 58000000 6960000 51040000))
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement