Copyright © 2005 Suradet Jitprapaikulsarn
สงวนลิขสิทธิ์ 2548 สุรเดช จิตประไพกุลศาล

Homework 1 (Due Sunday 12 June 2548)

Write the following programs or functions in one single file.  Solution.

  1. Write a program to convert degrees from Kelvin unit to Celsius unit.
;----------------------------------------------------------------------------
; @description convert degree from Celsius unit to Fahrenheit unit
; @param degree in celsius unit
; @return degree in Fahrenheit unit
; @contract C->F : number -> number
; @example (C->F 0) = 32
; @example (C->F -40) = -40
; @example (C->F 100) = 212
;----------------------------------------------------------------------------
(define (C->F x)
  (+ (* (/ x 5) 9) 32))

;------
; Test
;------
(C->F 0)
(C->F -40)
(C->F 100)
  1. Write a program to convert degrees from Celsius unit to Fahrenheit unit.
;----------------------------------------------------------------------------
; @description convert degree from Kelvin unit to Celsius unit
; @param degree in Kelvin unit
; @return degree in Celsius unit
; @contract K->C : number -> number
; @example (K->C 0) = -273
; @example (K->C 100) = -173
; @example (K->C 273) = 0
;----------------------------------------------------------------------------
(define (K->C x)
  (- x 273))

;------
; Test
;------
(K->C 0)
(K->C 100)
(K->C 273)

  1. Write a program to convert degrees from Kelvin unit to Fahrenheit unit.  This program must use the above two functions.
;----------------------------------------------------------------------------
; @description convert degree from Kelvin unit to Fahrenheit unit
; @param degree in Kelvin unit
; @return degree in Fahrenheit unit
; @contract K->F : number -> number
; @example (K->F 273) = 32
; @example (K->F 233) = -40
; @example (K->F 574.25) = 574.25
;----------------------------------------------------------------------------
(define (K->F x)
  (C->F (K->C x)))

;------
; Test
;------
(K->F 273)
(K->F 233)
(K->F 574.25)