home *** CD-ROM | disk | FTP | other *** search
- { Temperature }
- { ------------------------------------------------------
- Specification for Temperature class
- Variables:
- Value : real;
- The value of the temperature object is
- stored here as a real number. The
- temperature is stored in Celsius
- degrees.
-
- Procedures:
- .Init( T : real; DegType : char );
- The value in T is stored in the Value
- slot. The value of DegType tells the
- object the units of the temperature being
- stored. If the value of DegType is not
- 'F' (Fahrenheit), the temperature is
- stored in degrees Celsius.
-
- Functions:
- .GetTempC
- Returns the temperature expressed in
- Celsius.
- .GetTempF
- Returns the temperature expressed in
- Fahrenheit.
- ---------------------------------------------------------}
- type
-
- Temperature = object
- Value : real;
- procedure PutTemp( T : real; DegType : char );
- function GetTempC : real;
- function GetTempF : real;
- end;
-
- procedure Temperature.PutTemp( T : real; DegType : char );
- begin
- Value := T;
- if DegType = 'F' then
- Value := (T - 32) * 5/9;
- end;
-
-
- function Temperature.GetTempC : real;
- begin
- GetTempC := Value;
- end;
-
-
- function Temperature.GetTempF : real;
- begin
- GetTempF := (Value * 9/5) + 32;
- end;
-
-
- var
- A,B,C : Temperature;
-
- begin
- A.PutTemp(32,'F');
- writeln('Temperature A is ', A.GetTempC:2:2, ' deg C');
- writeln('Temperature A is ', A.GetTempF:2:2, ' deg F');
-
- B.PutTemp(100,'F');
- writeln('Temperature B is ', B.GetTempC:2:2, ' deg C');
- writeln('Temperature B is ', B.GetTempF:2:2, ' deg F');
-
- C.PutTemp( -40,'F');
- writeln('Temperature C is ', C.GetTempC:2:2, ' deg C');
- writeln('Temperature C is ', C.GetTempF:2:2, ' deg F');
-
- end.
-
-
- { Listing 1-3 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-