Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 1.70 KB | None | 0 0
  1. note
  2.   description: "Temperature."
  3.  
  4. class
  5.   TEMPERATURE
  6.  
  7. create
  8.   make_celsius, make_kelvin
  9.  
  10. feature — Initialization
  11.  
  12.   make_celsius (v: INTEGER)
  13.       — Create with Celsius value `v'.
  14.    require
  15.      temperature_valid: v >= -273
  16.    do
  17.      — Create a temperature object encapsulating value 'v' intended in Celsius.
  18.      — Your code here
  19.      celsius := v
  20.    ensure
  21.      celsius_set: celsius = v
  22.    end
  23.  
  24.  make_kelvin (v: INTEGER)
  25.      — Create with Kelvin value `v'.
  26.     require
  27.       temperature_valid: v >= 0
  28.     do
  29.       — Your code here
  30.       — Create a temperature object encapsulating value 'v' intended in Kelvin.
  31.       celsius := v - 273
  32.     ensure
  33.       celsius_set: celsius = v - 273
  34.       kelvin_set: kelvin = v
  35.     end
  36.  
  37. feature — Access
  38.  
  39.   celsius: INTEGER
  40.       — Value in Celsius scale.
  41.  
  42.   kelvin: INTEGER
  43.       — Value in Kelvin scale.
  44.     do
  45.       — Your code here
  46.       — Compute the Kelvin temperature value from the Celsius value
  47.       Result := celsius + 273
  48.     end
  49.  
  50. feature — Measurement
  51.  
  52.   average (other: TEMPERATURE): TEMPERATURE
  53.       — Average temperature between `Current' and `other'.
  54.     require
  55.       valid_temperature_object: other /= Void
  56.     do
  57.       — Your code here.
  58.       — Compute the average of two temperature. One is given by the current object,
  59.       — the other is passed as an argument.
  60.       create Result.make_celsius ((Current.celsius + other.celsius) // 2)
  61.     ensure
  62.       (Result.celsius >= other.celsius and Result.celsius <= Current.celsius) or (Result.celsius >= Current.celsius and Result.celsius <= other.celsius)
  63.     end
  64.  
  65. invariant
  66.   never_below_zero: kelvin >= 0
  67.  
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement