Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- note
- description : "Temperature application root class"
- class
- APPLICATION
- create
- execute
- feature {NONE} -- Initialization
- temperature_celsius,temperature_kelvin: INTEGER
- make_celsius1, make_kelvin1: TEMPERATURE
- execute
- -- Run application.
- do
- -- Input temperature in Celsius and show the converted value in Kelvin.
- Io.put_string ("Enter the first temperature in Celsius: ")
- Io.read_integer
- temperature_celsius := Io.last_integer
- Io.put_string ("The first temperature in Kelvin is: ")
- create make_celsius1.make_celsius (temperature_celsius) -- Creation prozedure, da Feature make_kelvin/celsius als create in Klasse TEMPERATURE definiert ist.
- Io.put_integer_32 (make_celsius1.kelvin)
- -- Input temperature in Kelvin and show the converted value in Celsius.
- Io.put_string ("%N"+"%N"+"Enter the second temperature in Kelvin: ")
- Io.read_integer
- temperature_kelvin := Io.last_integer
- Io.put_string ("The second temperature in Celsius is: ")
- create make_kelvin1.make_kelvin (temperature_kelvin)
- Io.put_integer_32 (make_kelvin1.celsius)
- -- Calculate the average temperature and show it in both Celsius and Kelvin.
- Io.put_string ("%N"+"%N"+"The avarage in Celsius is: ")
- Io.put_integer_32 (make_celsius1.average (make_celsius1))
- -- Io.put_string ("%N"+"The avarage in Kelvin is: ")
- end
- end
- note
- description: "Temperature."
- class
- TEMPERATURE
- create
- make_celsius, make_kelvin
- feature -- Initialization
- temperature_celsius, temperature_kelvin: INTEGER
- make_celsius (v: INTEGER)
- -- Create with Celsius value `v'.
- do
- -- Create a temperature object encapsulating value 'v' intended in Celsius.
- temperature_celsius := v
- end
- make_kelvin (v: INTEGER)
- -- Create with Kelvin value `v'.
- do
- -- Create a temperature object encapsulating value 'v' intended in Kelvin.
- temperature_kelvin := v
- end
- feature -- Access
- celsius: INTEGER
- -- Value in Celsius scale.
- do
- Result := temperature_kelvin-273
- end
- kelvin: INTEGER
- -- Value in Kelvin scale.
- do
- Result := temperature_celsius+273
- end
- feature -- Measurement
- average (other: TEMPERATURE): INTEGER --TEMPERATURE
- -- Average temperature between `Current' and `other'.
- do
- -- Compute the average of two temperature. One is given by the current object,
- -- the other is passed as an argument.
- Result := ( temperature_kelvin)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement