Advertisement
ProGramm

Assignment 4: 2 - Temperature application

Oct 12th, 2014
3,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 2.45 KB | None | 0 0
  1. note
  2.     description : "Temperature application root class"
  3.  
  4. class
  5.     APPLICATION
  6.  
  7.  
  8. create
  9.     execute
  10.  
  11. feature {NONE} -- Initialization
  12.     temperature_celsius,temperature_kelvin: INTEGER
  13.     make_celsius1, make_kelvin1: TEMPERATURE
  14.  
  15.     execute
  16.             -- Run application.
  17.         do
  18.             -- Input temperature in Celsius and show the converted value in Kelvin.
  19.             Io.put_string ("Enter the first temperature in Celsius: ")
  20.             Io.read_integer
  21.             temperature_celsius := Io.last_integer
  22.             Io.put_string ("The first temperature in Kelvin is: ")
  23.             create make_celsius1.make_celsius (temperature_celsius)     -- Creation prozedure, da Feature make_kelvin/celsius als create in Klasse TEMPERATURE definiert ist.
  24.             Io.put_integer_32 (make_celsius1.kelvin)
  25.  
  26.             -- Input temperature in Kelvin and show the converted value in Celsius.
  27.             Io.put_string ("%N"+"%N"+"Enter the second temperature in Kelvin: ")
  28.             Io.read_integer
  29.             temperature_kelvin := Io.last_integer
  30.             Io.put_string ("The second temperature in Celsius is: ")
  31.             create make_kelvin1.make_kelvin (temperature_kelvin)
  32.             Io.put_integer_32 (make_kelvin1.celsius)
  33.  
  34.             -- Calculate the average temperature and show it in both Celsius and Kelvin.
  35.             Io.put_string ("%N"+"%N"+"The avarage in Celsius is: ")
  36.             Io.put_integer_32 (make_celsius1.average (make_celsius1))
  37. --          Io.put_string ("%N"+"The avarage in Kelvin is: ")
  38.  
  39.         end
  40.  
  41. end
  42.  
  43.  
  44.  
  45.  
  46.  
  47. note
  48.     description: "Temperature."
  49.  
  50. class
  51.     TEMPERATURE
  52.  
  53. create
  54.     make_celsius, make_kelvin
  55.  
  56. feature -- Initialization
  57.     temperature_celsius, temperature_kelvin: INTEGER
  58.  
  59.     make_celsius (v: INTEGER)
  60.             -- Create with Celsius value `v'.
  61.         do
  62.             -- Create a temperature object encapsulating value 'v' intended in Celsius.
  63.             temperature_celsius := v
  64.         end
  65.  
  66.     make_kelvin (v: INTEGER)
  67.             -- Create with Kelvin value `v'.
  68.         do
  69.             -- Create a temperature object encapsulating value 'v' intended in Kelvin.
  70.             temperature_kelvin := v
  71.         end
  72.  
  73. feature -- Access
  74.  
  75.     celsius: INTEGER
  76.             -- Value in Celsius scale.
  77.         do
  78.             Result := temperature_kelvin-273
  79.         end
  80.  
  81.     kelvin: INTEGER
  82.             -- Value in Kelvin scale.
  83.         do
  84.             Result := temperature_celsius+273
  85.         end
  86.  
  87.  
  88. feature -- Measurement
  89.  
  90.     average (other: TEMPERATURE): INTEGER   --TEMPERATURE
  91.             -- Average temperature between `Current' and `other'.
  92.         do
  93.             -- Compute the average of two temperature. One is given by the current object,
  94.             -- the other is passed as an argument.
  95.             Result := ( temperature_kelvin)
  96.  
  97.         end
  98.  
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement