Pcs2d

Calculadora de mierda

Mar 9th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.99 KB | None | 0 0
  1. (define-struct punto (x y));estructura
  2. ;---
  3. (define puntopollo (make-punto 12 4));variable
  4. (define puntogallina (make-punto 45 3));variable
  5. ;+++
  6. (define (suma x y)
  7.   (+ x y))
  8. (define (resta x y)
  9.   (- x y))
  10. (define (multiplicacion x y)
  11.   (* x y))
  12. (define (division x y)
  13.   (if (= y 0)
  14.       "no se divide por cero"
  15.       (/ x y)))
  16. ;---
  17. (define (deltaequis x y)
  18.   (- (punto-x y) (punto-x x)))
  19. (define (deltaye x y)
  20.   (- (punto-y y) (punto-y x)))
  21. ;+++
  22. (define (distancia d1 d2)
  23.   (sqrt(+ (sqr (deltaequis d1 d2)) (sqr (deltaye d1 d2)))))
  24. ;---
  25. (define (puntomedio m1 m2)
  26.   (make-punto (/ (deltaequis m1 m2) 2) (/ (deltaye m1 m2) 2)))
  27. ;+++
  28. (define (puntopendiente1 p1 p2)
  29.   (cond
  30.     [(< (punto-y p1) 0) (if (< (punto-y p2) (punto-y p1)) (- (punto-y p2) (punto-y p1)) (- (punto-y p1) (punto-y p2)))]
  31.     [else (if (< (punto-y p1) (punto-y p2)) (- (punto-y p1) (punto-y p2)) (- (punto-y p2) (punto-y p1)))]))
  32. (define (puntopendiente2 p1 p2)
  33.   (cond
  34.     [(< (punto-x p1) 0) (if (< (punto-x p2) (punto-x p1)) (- (punto-x p2) (punto-x p1)) (- (punto-x p1) (punto-x p2)))]
  35.     [else (if (< (punto-x p1) (punto-x p2)) (- (punto-x p1) (punto-x p2)) (- (punto-x p2) (punto-x p1)))]))
  36.  
  37. (define (pendientereal p1 p2)
  38.   (/ (puntopendiente1 p1 p2) (puntopendiente2 p1 p2)))
  39. ;---------
  40. (define (calcular operacion variable1 variable2)
  41.   (cond
  42.     [(and (symbol? operacion) (number? variable1) (number? variable2))
  43.      (cond
  44.        [(symbol=? operacion 'sumasimple) (suma variable1 variable2)]
  45.        [(symbol=? operacion 'restasimple) (resta variable1 variable2)]
  46.        [(symbol=? operacion 'multiplicacionsimple) (multiplicacion variable1 variable2)]
  47.        [(symbol=? operacion 'divisionsimple) (division variable1 variable2)])]
  48.     [(and (symbol? operacion) (punto? variable1) (punto? variable2))
  49.      (cond
  50.        [(symbol=? operacion 'sumapuntosx) (suma (punto-x variable1) (punto-x variable2))]
  51.        [(symbol=? operacion 'restapuntosx) (resta (punto-x variable1) (punto-x variable2))]
  52.        [(symbol=? operacion 'multiplicapuntosx) (multiplicacion (punto-x variable1) (punto-x variable2))]
  53.        [(symbol=? operacion 'dividepuntosx) (division (punto-x variable1) (punto-x variable2))]
  54.        [(symbol=? operacion 'sumapuntosy) (suma (punto-y variable1) (punto-y variable2))]
  55.        [(symbol=? operacion 'restapuntosy) (resta (punto-y variable1) (punto-y variable2))]
  56.        [(symbol=? operacion 'multiplicapuntosy) (multiplicacion (punto-y variable1) (punto-y variable2))]
  57.        [(symbol=? operacion 'dividepuntosy) (division (punto-y variable1) (punto-y variable2))]
  58.        [(symbol=? operacion 'deltaequis) (deltaequis variable1 variable2)]
  59.        [(symbol=? operacion 'deltaye) (deltaye variable1 variable2)]
  60.        [(symbol=? operacion 'distancia) (distancia variable1 variable2)]
  61.        [(symbol=? operacion 'puntomedio) (puntomedio variable1 variable2)]
  62.        [(symbol=? operacion 'pendiente) (pendientereal variable1 variable2)]
  63.        [else "gononea"])]
  64.     [else "me la metio en reversa"]))
Advertisement
Add Comment
Please, Sign In to add comment