Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-struct inventario-electrodomesticos (electrodomestico1 electrodomestico2 electrodomestico3))
- (define-struct electrodomestico (nombre consumo-kwh horasFuncionando))
- (define-struct total-gasto (Gastokwh Pago))
- (define inventario-electroA (make-inventario-electrodomesticos (make-electrodomestico 'nevera 10 20)
- (make-electrodomestico 'tv 15 10)
- (make-electrodomestico 'computador 20 30)
- ))
- (define (calcular-costo-energia inventarioElectro)
- (cond
- [(not (inventario-electrodomesticos? inventarioElectro)) "Ingrese un dato tipo inventario-electrodomesticos"]
- [(equal? (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico1 inventarioElectro)))
- (make-total-gasto
- (GastoKwh inventarioElectro)
- (cond
- [(and (>= (GastoKwh inventarioElectro) 0) (<= (GastoKwh inventarioElectro) 300))
- (* (GastoKwh inventarioElectro) 50)]
- [(and (> (GastoKwh inventarioElectro) 300) (<= (GastoKwh inventarioElectro) 500))
- (+ (* 300 50)(* 100 (- (GastoKwh inventarioElectro) 300)))
- ]
- [(and (> (GastoKwh inventarioElectro) 500) (<= (GastoKwh inventarioElectro) 1000))
- (+ (* 300 50)(* 100 200)(* 150 (- (GastoKwh inventarioElectro) 500)))
- ]
- [(> (GastoKwh inventarioElectro) 1000)
- (+ (* 300 50)(* 100 200)(* 150 500 )(* 200 (- (GastoKwh inventarioElectro) 1000)))
- ]
- [else "Los kwh deben ser mayores o iguales a 0"]
- )
- )]
- [(equal? (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico2 inventarioElectro)))
- (make-total-gasto
- (GastoKwh inventarioElectro)
- (cond
- [(and (>= (GastoKwh inventarioElectro) 0) (<= (GastoKwh inventarioElectro) 300))
- (* (GastoKwh inventarioElectro) 50)]
- [(and (> (GastoKwh inventarioElectro) 300) (<= (GastoKwh inventarioElectro) 500))
- (+ (* 300 50)(* 100 (- (GastoKwh inventarioElectro) 300)))
- ]
- [(and (> (GastoKwh inventarioElectro) 500) (<= (GastoKwh inventarioElectro) 1000))
- (+ (* 300 50)(* 100 200)(* 150 (- (GastoKwh inventarioElectro) 500)))
- ]
- [(> (GastoKwh inventarioElectro) 1000)
- (+ (* 300 50)(* 100 200)(* 150 500 )(* 200 (- (GastoKwh inventarioElectro) 1000)))
- ]
- [else "Los kwh deben ser mayores o iguales a 0"]
- )
- )]
- [(equal? (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico3 inventarioElectro)))
- (make-total-gasto
- (GastoKwh inventarioElectro)
- (cond
- [(and (>= (GastoKwh inventarioElectro) 0) (<= (GastoKwh inventarioElectro) 300))
- (* (GastoKwh inventarioElectro) 50)]
- [(and (> (GastoKwh inventarioElectro) 300) (<= (GastoKwh inventarioElectro) 500))
- (+ (* 300 50)(* 100 (- (GastoKwh inventarioElectro) 300)))
- ]
- [(and (> (GastoKwh inventarioElectro) 500) (<= (GastoKwh inventarioElectro) 1000))
- (+ (* 300 50)(* 100 200)(* 150 (- (GastoKwh inventarioElectro) 500)))
- ]
- [(> (GastoKwh inventarioElectro) 1000)
- (+ (* 300 50)(* 100 200)(* 150 500 )(* 200 (- (GastoKwh inventarioElectro) 1000)))
- ]
- [else "Los kwh deben ser mayores o iguales a 0"]
- )
- )]
- [else (error "intentalo nuevamente")]
- ))
- ;;Gastokw
- (define (GastoKwh inventarioElectro)
- (cond
- [(inventario-electrodomesticos? inventarioElectro)
- (cond
- [(equal? (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico1 inventarioElectro)))
- (+ (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- )
- (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- )
- (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- )
- )]
- [(equal? (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico2 inventarioElectro)))
- (+ (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- )
- (*(electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- )
- (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- )
- )]
- [(equal? (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- (electrodomestico-nombre (inventario-electrodomesticos-electrodomestico3 inventarioElectro)))
- (+ (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico3 inventarioElectro))
- )
- (* (electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico2 inventarioElectro))
- )
- (*(electrodomestico-consumo-kwh(inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- (electrodomestico-horasFuncionando (inventario-electrodomesticos-electrodomestico1 inventarioElectro))
- ))
- ]
- [else (error "intentalo nuevamente")]
- )]
- [else "Ingrese un dato tipo inventario-electrodomesticos"]
- ))
- (calcular-costo-energia inventario-electroA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement