How to resolve the algorithm Temperature conversion step by step in the Amazing Hopper programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Temperature conversion step by step in the Amazing Hopper programming language
Table of Contents
Problem Statement
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. The Fahrenheit and Rankine scales also have the same magnitude, but different null points. The Celsius/Kelvin and Fahrenheit/Rankine scales have a ratio of 5 : 9.
Write code that accepts a value of kelvin, converts it to values of the three other scales, and prints the result.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Temperature conversion step by step in the Amazing Hopper programming language
Source code in the amazing programming language
/* MISTRAL - a flavour of Hopper */
#include
INICIAR:
TAMAÑO DE MEMORIA 20
temperatura=0
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
TOMAR("KELVIN : ",temperatura, NL)
CON( "CELSIUS : ", temperatura ), CALCULAR( Conversión Kelvin a Celsius ), NUEVA LÍNEA
CON( "FAHRENHEIT : ", temperatura ), CALCULAR( Conversión Kelvin a Fahrenheit ), NUEVA LÍNEA
CON( "RANKINE : ", temperatura ), CALCULAR( Conversión Kelvin a Rankine ), NUEVA LÍNEA
IMPRIMIR CON SALTO
FINALIZAR
SUBRUTINAS
FUNCIÓN(Conversión Kelvin a Celsius, k)
REDONDEAR(RESTAR(k, 273.15), 2)
RETORNAR
FUNCIÓN( Conversión Kelvin a Fahrenheit, k)
REDONDEAR( {k} MULTIPLICADO POR(1.8) MENOS( 459.67), 2)
RETORNAR
FUNCIÓN( Conversión Kelvin a Rankine, k)
RETORNAR ( {k} POR (1.8), REDONDEADO AL DECIMAL(2) )
/* MISTRAL - a flavour of Hopper */
#include
INICIAR:
temperatura=0
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
IMPRIMIR("KELVIN : ",temperatura, NL)
IMPRIMIR("CELSIUS : ",temperatura, MENOS '273.15', NL)
IMPRIMIR("FAHRENHEIT : ",temperatura, POR '1.8' MENOS '459.67', NL)
IMPRIMIR("RANKINE : ",temperatura, POR '1.8', NL)
FINALIZAR
#include
INICIAR:
TAMAÑO DE MEMORIA 15
temperatura=0
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
IMPRIMIR("KELVIN : ", temperatura, NL,\
"CELSIUS : ", {temperatura} MENOS '273.15', NL,\
"FAHRENHEIT : ", {temperatura} POR '1.8' MENOS '459.67', NL,\
"RANKINE : ", {temperatura} POR '1.8', NL)
FINALIZAR
#include
INICIAR:
TAMAÑO DE MEMORIA 20
temperatura=0, rankine=0
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
IMPRIMIR("KELVIN : ", temperatura, NL,\
"CELSIUS : ", {temperatura} MENOS '273.15', NL,\
"FAHRENHEIT : ", {temperatura} POR '1.8' ---RESPALDE EN 'rankine'--- MENOS '459.67', NL,\
"RANKINE : ", rankine, NL)
FINALIZAR
You may also check:How to resolve the algorithm Munching squares step by step in the GLSL programming language
You may also check:How to resolve the algorithm Here document step by step in the Scala programming language
You may also check:How to resolve the algorithm ABC problem step by step in the Raku programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Lua programming language
You may also check:How to resolve the algorithm Menu step by step in the VBScript programming language