conversion.rkt (CS 135 Assignment 1)

The instructions for this code is located here.

```#lang racket

; defines a constant, gallon->litres, that represents the number of litres in one gallon
; units are L/g
(define gallon->litres 3.78541)

; givens: ounces, gallon->litres, # of gallons = oz / (128 oz/gallon)
; procedure: ml = (# of gallons)(gallon->litres)(1000)
; procedure in units: ml = (g)(L/g)(1000 ml/L)
; parameter: fluid ounces
; returns: equivalent volume in ml
(define (floz->ml floz)
(* (/ floz 128) gallon->litres 1000))

; defines a constant, miles->km, that represents the number of kilometers in one mile
(define miles->km 1.60934)

; defines a function that converts mpg to lp100km
; givens: mpg, gallons/L, km/mile
; procedue: (m/g)(1 / (L/g)) = (m / L)(km / m) = (km / L). Then 1 / (km/L) = L/km. Return (L/km) * 100 (need 100 times more litres for 100km than 1 km)
; paramater: miles-per-gallon
; returns: same efficiency as parameters, but in units litres-per-100km
(define (mpg->lp100km mpg)
;  (/ 1 (* (* (* mpg (/ 1 gallon->litres)) miles->km) 100))) ; too small by factor of 1000 (put 100 in denominator.
;  (* (/ 1 (* (* mpg (/ 1 gallon->litres)) miles->km)) 100)) ; correct

(define mpl (* mpg (/ 1 gallon->litres))) ; miles per litre
(define kmpl (* mpl miles->km)) ; kilometers per litre
(define lpkm (/ 1 kmpl)) ; litre per km
(define lp100km (* lpkm 100)) ; litre per 100km (need 100 times more litres for 100km than 1 km)

lp100km)

; defines a function that converts lp100km to mpg
; givens: lp100km, g/L, km/m
; procedue: mpg = (lp100km/100)->(L/km). (1/(L/km))->(km/L)(1 / (km/m))->(m/L)(L/g) = m/g
; paramater: litres per 100km
; returns: same efficiency as parameters, but in units miles per gallon
(define (lp100km->mpg lp100km)

(define lpkm (/ lp100km 100)) ; litres per km
(define kmpl (/ 1 lpkm)) ; km per litre
(define mpl (* kmpl (/ 1 miles->km))) ; miles per litre
(define mpg (* mpl gallon->litres)) ; miles per gallon

mpg)
```