Browse Source

Added High/liw/Ord/Pred/Succ

michael 27 năm trước cách đây
mục cha
commit
8b404b158d
3 tập tin đã thay đổi với 47 bổ sung4 xóa
  1. 2 1
      docs/refex/README
  2. 7 3
      docs/refex/ex45.pp
  3. 38 0
      docs/refex/ex80.pp

+ 2 - 1
docs/refex/README

@@ -47,7 +47,7 @@ ex41.pp contains an example of the MemAvail function.
 ex42.pp contains an example of the Move function.
 ex43.pp contains an example of the Odd function.
 ex44.pp contains an example of the Ofs function.
-ex45.pp contains an example of the Ord function.
+ex45.pp contains an example of the Ord, Pred and Succ functions.
 ex46.pp contains an example of the ParamCount and ParamStr functions.
 ex47.pp contains an example of the Pi function.
 ex48.pp contains an example of the Pos function.
@@ -82,3 +82,4 @@ ex76.pp contains an example of the FillWord function.
 ex77.pp contains an example of the Rename function.
 ex78.pp contains an example of the Power function.
 ex79.pp contains an example of the SetJmp/LongJmp functions.
+ex80.pp contains an example of the High/Low functions.

+ 7 - 3
docs/refex/ex45.pp

@@ -1,6 +1,6 @@
 Program Example45;
 
-{ Program to demonstrate the Ord function. }
+{ Program to demonstrate the Ord,Pred,Succ functions. }
 
 Type
   TEnum = (Zero, One, Two, Three, Four);
@@ -11,7 +11,11 @@ Var
   
 begin
   X:=125;
-  Writeln (Ord(X));   { Prints 125 }
+  Writeln (Ord(X));  { Prints 125 }
+  X:=Pred(X);
+  Writeln (Ord(X));  { prints 124 }
   Y:= One;
-  Writeln (Ord(y));   { Prints 1 }
+  Writeln (Ord(y));  { Prints 1 }
+  Y:=Succ(Y);
+  Writeln (Ord(Y));  { Prints 2}
 end.

+ 38 - 0
docs/refex/ex80.pp

@@ -0,0 +1,38 @@
+Program example80;
+
+{ Example to demonstrate the High and Low functions. }
+
+Type TEnum = ( North, East, South, West );
+     TRange = 14..55;
+     TArray = Array [2..10] of Longint;
+    
+Function Average (Row : Array of Longint) : Real;
+
+Var I : longint;
+    Temp : Real;
+   
+   
+begin
+  Temp := Row[0];
+  For I := 1 to High(Row) do
+     Temp := Temp + Row[i];
+  Average := Temp / (High(Row)+1);
+end;
+                  
+Var A : TEnum;
+    B : TRange;
+    C : TArray;
+    I : longint;
+    
+begin
+  Writeln ('TEnum  goes from : ',Ord(Low(TEnum)),' to ', Ord(high(TEnum)),'.');
+  Writeln ('A      goes from : ',Ord(Low(A)),' to ', Ord(high(A)),'.');
+  Writeln ('TRange goes from : ',Ord(Low(TRange)),' to ', Ord(high(TRange)),'.');
+  Writeln ('B      goes from : ',Ord(Low(B)),' to ', Ord(high(B)),'.');
+  Writeln ('TArray index goes from : ',Ord(Low(TArray)),' to ', Ord(high(TArray)),'.');
+  Writeln ('C index      goes from : ',Low(C),' to ', high(C),'.');
+  For I:=Low(C) to High(C) do
+    C[i]:=I;
+  Writeln ('Average :',Average(c));  
+end.
+