Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-struct punto (x y));estructura
- ;---
- (define puntopollo (make-punto 12 4));variable
- (define puntogallina (make-punto 45 3));variable
- ;+++
- (define (suma x y)
- (+ x y))
- (define (resta x y)
- (- x y))
- (define (multiplicacion x y)
- (* x y))
- (define (division x y)
- (if (= y 0)
- "no se divide por cero"
- (/ x y)))
- ;---
- (define (deltaequis x y)
- (- (punto-x y) (punto-x x)))
- (define (deltaye x y)
- (- (punto-y y) (punto-y x)))
- ;+++
- (define (distancia d1 d2)
- (sqrt(+ (sqr (deltaequis d1 d2)) (sqr (deltaye d1 d2)))))
- ;---
- (define (puntomedio m1 m2)
- (make-punto (/ (deltaequis m1 m2) 2) (/ (deltaye m1 m2) 2)))
- ;+++
- (define (puntopendiente1 p1 p2)
- (cond
- [(< (punto-y p1) 0) (if (< (punto-y p2) (punto-y p1)) (- (punto-y p2) (punto-y p1)) (- (punto-y p1) (punto-y p2)))]
- [else (if (< (punto-y p1) (punto-y p2)) (- (punto-y p1) (punto-y p2)) (- (punto-y p2) (punto-y p1)))]))
- (define (puntopendiente2 p1 p2)
- (cond
- [(< (punto-x p1) 0) (if (< (punto-x p2) (punto-x p1)) (- (punto-x p2) (punto-x p1)) (- (punto-x p1) (punto-x p2)))]
- [else (if (< (punto-x p1) (punto-x p2)) (- (punto-x p1) (punto-x p2)) (- (punto-x p2) (punto-x p1)))]))
- (define (pendientereal p1 p2)
- (/ (puntopendiente1 p1 p2) (puntopendiente2 p1 p2)))
- ;---------
- (define (calcular operacion variable1 variable2)
- (cond
- [(and (symbol? operacion) (number? variable1) (number? variable2))
- (cond
- [(symbol=? operacion 'sumasimple) (suma variable1 variable2)]
- [(symbol=? operacion 'restasimple) (resta variable1 variable2)]
- [(symbol=? operacion 'multiplicacionsimple) (multiplicacion variable1 variable2)]
- [(symbol=? operacion 'divisionsimple) (division variable1 variable2)])]
- [(and (symbol? operacion) (punto? variable1) (punto? variable2))
- (cond
- [(symbol=? operacion 'sumapuntosx) (suma (punto-x variable1) (punto-x variable2))]
- [(symbol=? operacion 'restapuntosx) (resta (punto-x variable1) (punto-x variable2))]
- [(symbol=? operacion 'multiplicapuntosx) (multiplicacion (punto-x variable1) (punto-x variable2))]
- [(symbol=? operacion 'dividepuntosx) (division (punto-x variable1) (punto-x variable2))]
- [(symbol=? operacion 'sumapuntosy) (suma (punto-y variable1) (punto-y variable2))]
- [(symbol=? operacion 'restapuntosy) (resta (punto-y variable1) (punto-y variable2))]
- [(symbol=? operacion 'multiplicapuntosy) (multiplicacion (punto-y variable1) (punto-y variable2))]
- [(symbol=? operacion 'dividepuntosy) (division (punto-y variable1) (punto-y variable2))]
- [(symbol=? operacion 'deltaequis) (deltaequis variable1 variable2)]
- [(symbol=? operacion 'deltaye) (deltaye variable1 variable2)]
- [(symbol=? operacion 'distancia) (distancia variable1 variable2)]
- [(symbol=? operacion 'puntomedio) (puntomedio variable1 variable2)]
- [(symbol=? operacion 'pendiente) (pendientereal variable1 variable2)]
- [else "gononea"])]
- [else "me la metio en reversa"]))
Advertisement
Add Comment
Please, Sign In to add comment