This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,8 +1,8 @@
There are quite a number of temperature scales. For this task we will concentrate on 4 of the perhaps best-known ones: [[wp:Kelvin|Kelvin]], [[wp:Degree Celsius|Celcius]], [[wp:Fahrenheit|Fahrenheit]] and [[wp:Degree Rankine|Rankine]].
There are quite a number of temperature scales. For this task we will concentrate on 4 of the perhaps best-known ones: [[wp:Kelvin|Kelvin]], [[wp:Degree Celsius|Celsius]], [[wp:Fahrenheit|Fahrenheit]] and [[wp:Degree Rankine|Rankine]].
The Celcius and Kelvin scales have the same magnitude, but different null points.
The Celsius and Kelvin scales have the same magnitude, but different null points.
:0 degrees Celcius corresponds to '''273.15''' kelvin.
:0 degrees Celsius corresponds to '''273.15''' kelvin.
:0 kelvin is absolute zero.
The Fahrenheit and Rankine scales also have the same magnitude, but different null points.
@ -10,7 +10,7 @@ The Fahrenheit and Rankine scales also have the same magnitude, but different nu
:0 degrees Fahrenheit corresponds to '''459.67''' degrees Rankine.
:0 degrees Rankine is absolute zero.
The Celcius/Kelvin and Fahrenheit/Rankine scales have a ratio of '''5 : 9'''.
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 on the three other scales and prints the result. For instance:
<pre>

View file

@ -0,0 +1,20 @@
void
show(integer symbol, real temperature)
{
o_form("%c /d2p2w8/\n", symbol, temperature);
}
integer
main(void)
{
real k;
k = atof(argv(1));
show('K', k);
show('C', k - 273.15);
show('F', k * 1.8 - 459.67);
show('R', k * 1.8);
return 0;
}

View file

@ -5,7 +5,7 @@
50 LET F = K * 1.8 - 459.67
60 LET R = K * 1.8
70 PRINT K; " KELVIN IS EQUIVALENT TO"
80 PRINT C; " DEGREES CELCIUS"
80 PRINT C; " DEGREES CELSIUS"
90 PRINT F; " DEGREES FAHRENHEIT"
100 PRINT R; " DEGREES RANKINE"
110 GOTO 20

View file

@ -0,0 +1,9 @@
do
print "Kelvin degrees (>=0): ";
input K
until K>=0
print "K = " + string(K)
print "C = " + string(K - 273.15)
print "F = " + string(K * 1.8 - 459.67)
print "R = " + string(K * 1.8)

View file

@ -0,0 +1,46 @@
( ( rational2fixedpoint
= minus fixedpointnumber number decimals
. !arg:(#?number.~<0:~/#?decimals)
& ( !number:0&"0.0"
| ( !number:>0&
| -1*!number:?number&"-"
)
: ?minus
& !number+1/2*10^(-1*!decimals):?number
& !minus div$(!number.1) ".":?fixedpointnumber
& whl
' ( !decimals+-1:~<0:?decimals
& !fixedpointnumber
div$(mod$(!number.1)*10:?number.1)
: ?fixedpointnumber
)
& str$!fixedpointnumber
)
)
& ( fixedpoint2rational
= integerpart fractionalpart decimals
. @( !arg
: #?integerpart
( "." ?fractionalpart
| &0:?fractionalpart
)
)
& @(!fractionalpart:? #?fractionalpart [?decimals)
& !integerpart
+ (!integerpart:<0&-1|1)
* 10^(-1*!decimals)
* !fractionalpart
)
& whl
' ( put$"Enter Kelvin temperature:"
& fixedpoint2rational$(get'(,STR)):?kelvin
& !kelvin+-27315/100:?celcius
& (degree=.str$(chu$(x2d$b0) !arg))
& out$(rational2fixedpoint$(!kelvin.2) K)
& out$(rational2fixedpoint$(!celcius.2) degree$C)
& out$(rational2fixedpoint$(!celcius*9/5+32.2) degree$F)
& out$(rational2fixedpoint$(!kelvin*9/5.2) degree$Ra)
& out$(rational2fixedpoint$(!celcius*4/5.2) degree$Ré)
)
& done!
)

View file

@ -24,7 +24,7 @@ public:
cout << endl << left
<< "TEMPERATURES:" << endl
<< "===============" << endl << setw( 13 )
<< "CELCIUS:" << cel << endl << setw( 13 )
<< "CELSIUS:" << cel << endl << setw( 13 )
<< "DELISLE:" << del << endl << setw( 13 )
<< "FAHRENHEIT:" << fah << endl << setw( 13 )
<< "KELVIN:" << kelvin << endl << setw( 13 )

View file

@ -0,0 +1,36 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. temp-conversion.
DATA DIVISION.
WORKING-STORAGE SECTION.
78 Kelvin-Rankine-Ratio VALUE 0.5556. *> 5 / 9 to 4 d.p.
78 Kelvin-Celsius-Diff VALUE 273.15.
78 Rankine-Fahrenheit-Diff VALUE 459.67.
01 temp-kelvin PIC S9(8)V99.
01 temp-rankine PIC S9(8)V99.
01 kelvin PIC -(7)9.99.
01 celsius PIC -(7)9.99.
01 rankine PIC -(7)9.99.
01 fahrenheit PIC -(7)9.99.
PROCEDURE DIVISION.
DISPLAY "Enter a temperature in Kelvin to convert: " NO ADVANCING
ACCEPT temp-kelvin
MOVE temp-kelvin TO kelvin
DISPLAY "K " kelvin
SUBTRACT Kelvin-Celsius-Diff FROM temp-kelvin GIVING celsius
DISPLAY "C " celsius
DIVIDE temp-kelvin BY Kelvin-Rankine-Ratio
GIVING temp-rankine, rankine
SUBTRACT Rankine-Fahrenheit-Diff FROM temp-rankine GIVING fahrenheit
DISPLAY "F " fahrenheit
DISPLAY "R " rankine
GOBACK
.

View file

@ -0,0 +1,27 @@
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: k <Kelvin>")
return
}
k, err := strconv.ParseFloat(os.Args[1], 64)
if err != nil {
fmt.Println(err)
return
}
if k < 0 {
fmt.Println("Kelvin must be >= 0.")
return
}
fmt.Printf("K %.2f\n", k)
fmt.Printf("C %.2f\n", k-273.15)
fmt.Printf("F %.2f\n", k*9/5-459.67)
fmt.Printf("R %.2f\n", k*9/5)
}

View file

@ -0,0 +1,7 @@
procedure main(A)
k := A[1] | 21.00
write("K ",k)
write("C ",k-273.15)
write("R ",r := k*(9.0/5.0))
write("F ",r - 459.67)
end

View file

@ -5,7 +5,7 @@ public class TemperatureConversion {
double kelvin = Double.parseDouble(args[0]);
if (kelvin >= 0) {
System.out.printf("K %2.2f\n", kelvin);
System.out.printf("C %2.2f\n", kelvinToCelcius(kelvin));
System.out.printf("C %2.2f\n", kelvinToCelsius(kelvin));
System.out.printf("F %2.2f\n", kelvinToFahrenheit(kelvin));
System.out.printf("R %2.2f\n", kelvinToRankine(kelvin));
} else {
@ -17,7 +17,7 @@ public class TemperatureConversion {
}
}
public static double kelvinToCelcius(double k) {
public static double kelvinToCelsius(double k) {
return k + 273.15;
}

View file

@ -0,0 +1,185 @@
/* NetRexx */
options replace format comments java crossref symbols
numeric digits 20
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
+ Kelvin Celsius Fahrenheit Rankine Delisle Newton Réaumur Rømer
K T T-273.15 T*9/5-459.67 T*9/5 (373.15-T)*3/2 (T-273.15)*33/100 (T-273.15)*4/5 (T-273.15)*21/40+7.5
C T+273.15 T T*9/5+32 (T+273.15)*9/5 (100-T)*3/2 T*33/100 T*4/5 T*21/40+7.5
F (T+459.67)*5/9 (T-32)*5/9 T T+459.67 (212-T)*5/6 (T-32)*11/60 (T-32)*4/9 (T-32)*7/24+7.5
R T*5/9 (T-491.67)*5/9 T-459.67 T (671.67-T)*5/6 (T-491.67)*11/60 (T-491.67)*4/9 (T-491.67)*7/24+7.5
De 373.15-T*2/3 100-T*2/3 212-T*6/5 671.67-T*6/5 T 33-T*11/50 80-T*8/15 60-T*7/20
N T*100/33+273.15 T*100/33 T*60/11+32 T*60/11+491.67 (33-T)*50/11 T T*80/33 T*35/22+7.5
Ré T*5/4+273.15 T*5/4 T*9/4+32 T*9/4+491.67 (80-T)*15/8 T*33/80 T T*21/32+7.5
Rø (T-7.5)*40/21+273.15 (T-7.5)*40/21 (T-7.5)*24/7+32 (T-7.5)*24/7+491.67 (60-T)*20/7 (T-7.5)*22/35 (T-7.5)*32/21 T
*/
method temperatureConversion(scaleFrom, scaleTo, T) public static
parse 'KELVIN CELSIUS FAHRENHEIT RANKINE DELISLE NEWTON REAUMUR ROEMER' -
KELVIN CELSIUS FAHRENHEIT RANKINE DELISLE NEWTON REAUMUR ROEMER .
scaleFrom = scaleFrom.upper()
scaleTo = scaleTo.upper()
select label sF case scaleFrom
when KELVIN then do
select case scaleTo
when KELVIN then val = T
when CELSIUS then val = T - 273.15
when FAHRENHEIT then val = T * 9 / 5 - 459.67
when RANKINE then val = T * 9 / 5
when DELISLE then val = (373.15 - T) * 3 / 2
when NEWTON then val = (T - 273.15) * 33 / 100
when REAUMUR then val = (T - 273.15) * 4 / 5
when ROEMER then val = (T - 273.15) * 21 / 40 + 7.5
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when CELSIUS then do
select case scaleTo
when KELVIN then val = T + 273.15
when CELSIUS then val = T
when FAHRENHEIT then val = T * 9 / 5 + 32
when RANKINE then val = (T + 273.15) * 9 / 5
when DELISLE then val = (100 - T) * 3 / 2
when NEWTON then val = T * 33 / 100
when REAUMUR then val = T * 4 / 5
when ROEMER then val = T * 21 / 40 + 7.5
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when FAHRENHEIT then do
select case scaleTo
when KELVIN then val = (T + 459.67) * 5 / 9
when CELSIUS then val = (T - 32) * 5 / 9
when FAHRENHEIT then val = T
when RANKINE then val = T + 459.67
when DELISLE then val = (212 - T) * 5 / 6
when NEWTON then val = (T - 32) * 11 / 60
when REAUMUR then val = (T - 32) * 4 / 9
when ROEMER then val = (T - 32) * 7 / 24 + 7.5
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when RANKINE then do
select case scaleTo
when KELVIN then val = T * 5 / 9
when CELSIUS then val = (T - 491.67) * 5 / 9
when FAHRENHEIT then val = T - 459.67
when RANKINE then val = T
when DELISLE then val = (671.67 - T) * 5 / 6
when NEWTON then val = (T - 491.67) * 11 / 60
when REAUMUR then val = (T - 491.67) * 4 / 9
when ROEMER then val = (T - 491.67) * 7 / 24 + 7.5
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when DELISLE then do
select case scaleTo
when KELVIN then val = 373.15 - T * 2 / 3
when CELSIUS then val = 100 - T * 2 / 3
when FAHRENHEIT then val = 212 - T * 6 / 5
when RANKINE then val = 671.67 - T * 6 / 5
when DELISLE then val = T
when NEWTON then val = 33 - T * 11 / 50
when REAUMUR then val = 80 - T * 8 / 15
when ROEMER then val = 60 - T * 7 / 20
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when NEWTON then do
select case scaleTo
when KELVIN then val = T * 100 / 33 + 273.15
when CELSIUS then val = T * 100 / 33
when FAHRENHEIT then val = T * 60 / 11 + 32
when RANKINE then val = T * 60 / 11 + 491.67
when DELISLE then val = (33 - T) * 50 / 11
when NEWTON then val = T
when REAUMUR then val = T * 80 / 33
when ROEMER then val = T * 35 / 22 + 7.5
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when REAUMUR then do
select case scaleTo
when KELVIN then val = T * 5 / 4 + 273.15
when CELSIUS then val = T * 5 / 4
when FAHRENHEIT then val = T * 9 / 4 + 32
when RANKINE then val = T * 9 / 4 + 491.67
when DELISLE then val = (80 - T) * 15 / 8
when NEWTON then val = T * 33 / 80
when REAUMUR then val = T
when ROEMER then val = T * 21 / 32 + 7.5
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
when ROEMER then do
select case scaleTo
when KELVIN then val = (T - 7.5) * 40 / 21 + 273.15
when CELSIUS then val = (T - 7.5) * 40 / 21
when FAHRENHEIT then val = (T - 7.5) * 24 / 7 + 32
when RANKINE then val = (T - 7.5) * 24 / 7 + 491.67
when DELISLE then val = (60 - T) * 20 / 7
when NEWTON then val = (T - 7.5) * 22 / 35
when REAUMUR then val = (T - 7.5) * 32 / 21
when ROEMER then val = T
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end
end
otherwise
signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
end sF
return val
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) public static
tlist = [ -
/* C....... F....... K....... R.......*/ -
' 5500.00 9932.00 5773.15 10391.67', -
' 300.00 572.00 573.15 1031.67', -
' 200.00 392.00 473.15 851.67', -
' 100.00 212.00 373.15 671.67', -
' 37.00 98.60 310.15 558.27', -
' 0.00 32.00 273.15 491.67', -
' -100.00 -148.00 173.15 311.67', -
' -200.00 -328.00 73.15 131.67', -
' -252.15 -421.87 21.00 37.80', -
' -273.15 -459.67 0.00 0.00' -
]
parse 'CELSIUS FAHRENHEIT KELVIN RANKINE' CELSIUS FAHRENHEIT KELVIN RANKINE .
loop temp over tlist
parse temp ttC ttF ttK ttR .
say ' C....... F....... K....... R.......'
say 'C ' -
temperatureConversion(CELSIUS, CELSIUS, ttC).format(5, 2) -
temperatureConversion(CELSIUS, FAHRENHEIT, ttC).format(5, 2) -
temperatureConversion(CELSIUS, KELVIN, ttC).format(5, 2) -
temperatureConversion(CELSIUS, RANKINE, ttC).format(5, 2)
say 'F ' -
temperatureConversion(FAHRENHEIT, CELSIUS, ttF).format(5, 2) -
temperatureConversion(FAHRENHEIT, FAHRENHEIT, ttF).format(5, 2) -
temperatureConversion(FAHRENHEIT, KELVIN, ttF).format(5, 2) -
temperatureConversion(FAHRENHEIT, RANKINE, ttF).format(5, 2)
say 'K ' -
temperatureConversion(KELVIN, CELSIUS, ttK).format(5, 2) -
temperatureConversion(KELVIN, FAHRENHEIT, ttK).format(5, 2) -
temperatureConversion(KELVIN, KELVIN, ttK).format(5, 2) -
temperatureConversion(KELVIN, RANKINE, ttK).format(5, 2)
say 'R ' -
temperatureConversion(RANKINE, CELSIUS, ttR).format(5, 2) -
temperatureConversion(RANKINE, FAHRENHEIT, ttR).format(5, 2) -
temperatureConversion(RANKINE, KELVIN, ttR).format(5, 2) -
temperatureConversion(RANKINE, RANKINE, ttR).format(5, 2)
say
end temp
return

View file

@ -1,7 +1,7 @@
class Temperature {
function : Main(args : String[]) ~ Nil {
k := System.IO.Console->ReadString()->ToFloat();
c := KelvinToCelcius(k);
c := KelvinToCelsius(k);
f := KelvinToFahrenheit(k);
r := KelvinToRankine(k);
@ -11,7 +11,7 @@
"R: {$r}"->PrintLine();
}
function : KelvinToCelcius(k : Float) ~ Float {
function : KelvinToCelsius(k : Float) ~ Float {
return k - 273.15;
}

View file

@ -0,0 +1,148 @@
*process source attributes xref;
/* PL/I **************************************************************
* 15.08.2013 Walter Pachl translated from NetRexx
* temperatures below 0K are considered invalid
*********************************************************************/
temperature: Proc Options(main);
Dcl sysin record Input;
On Endfile(sysin) Goto eoj;
On Record(sysin);
Dcl 1 dat,
2 t Pic'SSSS9V.99',
2 * char( 1),
2 from char(10),
2 * char( 1),
2 to char(10);
Do Forever;
Read File(sysin) Into(dat);
If tc(t,from,'KELVIN')<0 Then
Put Edit('Input (',t,from,') invalid. Below absolute zero')
(Skip,a,f(8,2),x(1),a,a);
Else
Put edit(t,from,' -> ',tc(t,from,to),to)
(skip,f(8,2),x(1),a(10),a,f(8,2),x(1),a(10));
End;
eoj: Return;
tc: Procedure(T,scaleFrom,scaleTo) Returns(Dec Fixed(8,2));
Dcl t Pic'SSSS9V.99';
Dcl (val) Dec Fixed(8,2);
Dcl (scaleFrom,scaleTo) Char(10);
select(scaleFrom);
when('KELVIN ') do;
select(scaleTo);
when('KELVIN ') val = T;
when('CELSIUS ') val = T - 273.15;
when('FAHRENHEIT') val = T * 9 / 5 - 459.67;
when('RANKINE ') val = T * 9 / 5;
when('DELISLE ') val = (373.15 - T) * 3 / 2;
when('NEWTON ') val = (T - 273.15) * 33 / 100;
when('REAUMUR ') val = (T - 273.15) * 4 / 5;
when('ROEMER ') val = (T - 273.15) * 21 / 40 + 7.5;
otherwise Do;
Put Edit('scaleTo=',scaleTo)(Skip,a,a);
Call err(1);
End;
end;
end;
when('CELSIUS') do;
select(scaleTo);
when('KELVIN ') val = T + 273.15;
when('CELSIUS ') val = T;
when('FAHRENHEIT') val = T * 9 / 5 + 32;
when('RANKINE ') val = (T + 273.15) * 9 / 5;
when('DELISLE ') val = (100 - T) * 3 / 2;
when('NEWTON ') val = T * 33 / 100;
when('REAUMUR ') val = T * 4 / 5;
when('ROEMER ') val = T * 21 / 40 + 7.5;
otherwise Call err(2);
end;
end;
when('FAHRENHEIT') do;
select(scaleTo);
when('KELVIN ') val = (T + 459.67) * 5 / 9;
when('CELSIUS ') val = (T - 32) * 5 / 9;
when('FAHRENHEIT') val = T;
when('RANKINE ') val = T + 459.67;
when('DELISLE ') val = (212 - T) * 5 / 6;
when('NEWTON ') val = (T - 32) * 11 / 60;
when('REAUMUR ') val = (T - 32) * 4 / 9;
when('ROEMER ') val = (T - 32) * 7 / 24 + 7.5;
otherwise Call err(3);
end;
end;
when('RANKINE') do;
select(scaleTo);
when('KELVIN ') val = T * 5 / 9;
when('CELSIUS ') val = (T - 491.67) * 5 / 9;
when('FAHRENHEIT') val = T - 459.67;
when('RANKINE ') val = T;
when('DELISLE ') val = (671.67 - T) * 5 / 6;
when('NEWTON ') val = (T - 491.67) * 11 / 60;
when('REAUMUR ') val = (T - 491.67) * 4 / 9;
when('ROEMER ') val = (T - 491.67) * 7 / 24 + 7.5;
otherwise Call err(4);
end;
end;
when('DELISLE') do;
select(scaleTo);
when('KELVIN ') val = 373.15 - T * 2 / 3;
when('CELSIUS ') val = 100 - T * 2 / 3;
when('FAHRENHEIT') val = 212 - T * 6 / 5;
when('RANKINE ') val = 671.67 - T * 6 / 5;
when('DELISLE ') val = T;
when('NEWTON ') val = 33 - T * 11 / 50;
when('REAUMUR ') val = 80 - T * 8 / 15;
when('ROEMER ') val = 60 - T * 7 / 20;
otherwise Call err(5);
end;
end;
when('NEWTON') do;
select(scaleTo);
when('KELVIN ') val = T * 100 / 33 + 273.15;
when('CELSIUS ') val = T * 100 / 33;
when('FAHRENHEIT') val = T * 60 / 11 + 32;
when('RANKINE ') val = T * 60 / 11 + 491.67;
when('DELISLE ') val = (33 - T) * 50 / 11;
when('NEWTON ') val = T;
when('REAUMUR ') val = T * 80 / 33;
when('ROEMER ') val = T * 35 / 22 + 7.5;
otherwise Call err(6);
end;
end;
when('REAUMUR') do;
select(scaleTo);
when('KELVIN ') val = T * 5 / 4 + 273.15;
when('CELSIUS ') val = T * 5 / 4;
when('FAHRENHEIT') val = T * 9 / 4 + 32;
when('RANKINE ') val = T * 9 / 4 + 491.67;
when('DELISLE ') val = (80 - T) * 15 / 8;
when('NEWTON ') val = T * 33 / 80;
when('REAUMUR ') val = T;
when('ROEMER ') val = T * 21 / 32 + 7.5;
otherwise Call err(7);
end;
end;
when('ROEMER') do;
select(scaleTo);
when('KELVIN ') val = (T - 7.5) * 40 / 21 + 273.15;
when('CELSIUS ') val = (T - 7.5) * 40 / 21;
when('FAHRENHEIT') val = (T - 7.5) * 24 / 7 + 32;
when('RANKINE ') val = (T - 7.5) * 24 / 7 + 491.67;
when('DELISLE ') val = (60 - T) * 20 / 7;
when('NEWTON ') val = (T - 7.5) * 22 / 35;
when('REAUMUR ') val = (T - 7.5) * 32 / 21;
when('ROEMER ') val = T;
otherwise Call err(8);
end;
end;
otherwise Call err(9);
end;
return(val);
err: Proc(e);
Dcl e Dec fixed(1);
Put Edit('error ',e,' invalid input')(Skip,a,f(1),a);
val=0;
End;
End;
End;

View file

@ -3,6 +3,7 @@ parse arg tList /*get specified temperature lists*/
do until tList='' /*process a list of temperatures.*/
parse var tList x ',' tList /*temps are separated by commas. */
x=translate(x,'((',"[{") /*support other grouping symbols.*/
x=space(x); parse var x z '(' /*handle any comments (if any). */
if z=='' then call serr 'no arguments were specified.'
_=verify(z, '+-.0123456789') /*a list of valid number thingys.*/
@ -16,27 +17,66 @@ parse arg tList /*get specified temperature lists*/
uU=translate(u,'eE',"éÉ"); upper uU /*uppercase version of temp unit.*/
if left(uU,7)=='DEGREES' then uU=substr(uU,8) /*redundant "degrees"? */
if left(uU,5)=='DEGREE' then uU=substr(uU,7) /* " "degree" ? */
if left(uU,6)=='DEGREE' then uU=substr(uU,7) /* " "degree" ? */
uU=strip(uU)
if \datatype(n,'N') then call serr 'illegal number:' n
/*accept alternate spellings. */
select /*convert ──► ºF temperatures. */
when abbrev('CENTIGRADE', uU) |,
abbrev('CENTESIMAL', uU) |,
abbrev('CELSIUS' , uU) |,
abbrev('CELCIUS' , uU) then F=n * 9/5 + 32
when abbrev('DELISLE' , uU) then F=212 -(n * 6/5)
when abbrev('FAHRENHEIT', uU) then F=n
when abbrev('KELVIN' , uU) then F=n * 9/5 - 459.67
when abbrev('NEWTON' , uU) then F=n * 60/11 + 32
when abbrev('RANKINE' , uU) then F=n - 459.67
when abbrev('REAUMUR' , uU, 2) then F=n * 9/4 + 32
when abbrev('ROEMER' , uU, 2) |,
abbrev('ROMER' , uU, 2) then F=(n-7.5) * 27/4 + 32
otherwise call serr 'illegal temperature scale:' u
when abbrev('CENTIGRADE' , uU) |,
abbrev('CENTRIGRADE', uU) |, /* 50% misspelled.*/
abbrev('CETIGRADE' , uU) |, /* 50% misspelled.*/
abbrev('CENTINGRADE', uU) |,
abbrev('CENTESIMAL' , uU) |,
abbrev('CELCIUS' , uU) |, /* 82% misspelled.*/
abbrev('CELCIOUS' , uU) |, /* 4% misspelled.*/
abbrev('CELCUIS' , uU) |, /* 4% misspelled.*/
abbrev('CELSUIS' , uU) |, /* 2% misspelled.*/
abbrev('CELCEUS' , uU) |, /* 2% misspelled.*/
abbrev('CELCUS' , uU) |, /* 2% misspelled.*/
abbrev('CELISUS' , uU) |, /* 1% misspelled.*/
abbrev('CELSUS' , uU) |, /* 1% misspelled.*/
abbrev('CELSIUS' , uU) then F=n * 9/5 + 32
when abbrev('DELISLE' , uU) then F=212 -(n * 6/5)
when abbrev('FARENHEIT' , uU) |, /* 39% misspelled.*/
abbrev('FARENHEIGHT', uU) |, /* 15% misspelled.*/
abbrev('FARENHITE' , uU) |, /* 6% misspelled.*/
abbrev('FARENHIET' , uU) |, /* 3% misspelled.*/
abbrev('FARHENHEIT' , uU) |, /* 3% misspelled.*/
abbrev('FARINHEIGHT', uU) |, /* 2% misspelled.*/
abbrev('FARENHIGHT' , uU) |, /* 2% misspelled.*/
abbrev('FAHRENHIET' , uU) |, /* 2% misspelled.*/
abbrev('FERENHEIGHT', uU) |, /* 2% misspelled.*/
abbrev('FEHRENHEIT' , uU) |, /* 2% misspelled.*/
abbrev('FERENHEIT' , uU) |, /* 2% misspelled.*/
abbrev('FERINHEIGHT', uU) |, /* 1% misspelled.*/
abbrev('FARIENHEIT' , uU) |, /* 1% misspelled.*/
abbrev('FARINHEIT' , uU) |, /* 1% misspelled.*/
abbrev('FARANHITE' , uU) |, /* 1% misspelled.*/
abbrev('FAHRENHEIT' , uU) then F=n
when abbrev('KELVINS' , uU) |, /* 46% misspelled.*/
abbrev('KALVIN' , uU) |, /* 27% misspelled.*/
abbrev('KERLIN' , uU) |, /* 18% misspelled.*/
abbrev('KEVEN' , uU) |, /* 9% misspelled.*/
abbrev('KELVIN' , uU) then F=n * 9/5 - 459.67
when abbrev('NEUTON' , uU) |, /*100% misspelled.*/
abbrev('NEWTON' , uU) then F=n * 60/11 + 32
/*a single R is taken as Rankine.*/
when abbrev('RANKINE' , uU) then F=n - 459.67
when abbrev('REAUMUR' , uU, 2) then F=n * 9/4 + 32
when abbrev('ROEMER' , uU, 2) |,
abbrev('ROMER' , uU, 2) then F=(n-7.5) * 27/4 + 32
otherwise call serr 'illegal temperature scale:' u
end /*select*/
say right(' ' x,55,"")
say Tform( ( F - 32 ) * 5/9 ) 'Celcius'
say right(' ' x,55,"") /*show original value&scale, sep.*/
say Tform( ( F - 32 ) * 5/9 ) 'Celsius'
say Tform( ( 212 - F ) * 5/6 ) 'Delisle'
say Tform( F ) 'Fahrenheit'
say Tform( ( F + 459.67 ) * 5/9 ) 'Kelvin'
@ -44,12 +84,16 @@ parse arg tList /*get specified temperature lists*/
say Tform( F + 459.67 ) 'Rankine'
say Tform( ( F - 32 ) * 4/9 ) 'Reaumur'
say Tform( ( F - 32 ) * 7/24 + 7.5 ) 'Romer'
end /*until tlist=''*/
end /*until tlist='' */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────TFORM subroutine────────────────────*/
Tform: procedure; showDig=8; _=format(arg(1),,showDig)/1; p=pos('.',_)
if p==0 then _=_ || left('',showDig+1)
else _=_ || left('',showDig-length(_)+p); return right(_,20)
Tform: procedure; showDig=8 /*only show 8 significant digits.*/
_=format(arg(1),,showDig)/1 /*format arg 8 digs past the . */
p=pos('.',_) /*find position of decimal point.*/
/* [↓] align integers with FP #s.*/
if p==0 then _=_ || left('',showDig+1) /*no decimal point.*/
else _=_ || left('',showDig-length(_)+p) /*has " " */
return right(_,20) /*return the re-formatted arg. */
/*──────────────────────────────────SERR subroutine─────────────────────*/
serr: say; say '***error!***'; say; say arg(1); say; exit 13

View file

@ -1,5 +1,5 @@
[loop]
input "Lelvin Degrees";kelvin
input "Kelvin Degrees";kelvin
if kelvin <= 0 then end ' zero or less ends the program
celcius = kelvin - 273.15
fahrenheit = kelvin * 1.8 - 459.67

View file

@ -5,7 +5,7 @@
50 LET f = k * 1.8 - 459.67
60 LET r = k * 1.8
70 PRINT k; " Kelvin is equivalent to"
80 PRINT c; " Degrees Celcius"
80 PRINT c; " Degrees Celsius"
90 PRINT f; " Degrees Fahrenheit"
100 PRINT r; " Degrees Rankine"
110 GO TO 20