1.more about variable:
we know that the delcaraction of variable
is like this:
var
....:type;
....:type;
now we will more go deep in to the type:
except pascal build in TYPE like string,real,integer,char...etc,
we can also define a types for
our own use,the delcaration like this:
type
UserDefineType:Limit
sample 1:
type
lowerCase='a'..'z';
{ two full stop added between "from" and "to" according to ASCII code}
Upcase='A'..'Z';
char='a'..'Z';
{this line is invalid because of in ASCII code, a is greater than Z,and
char original is defined}
{then ,we can use them:}
var
small:lowercase;
big:lowercase;
except character,a group of date(like
monday) and number also accept.
B.ARRAY...
array is used to store a group of data
in type,it have many dimention:
let's see a simple array structure sample:
sample1:
{one dimention}
var
INTE:array [1..3] of integer;
begin
INTE[1]:=1;
INTE[2]:=2;
INTE[3]:=INTE[2]+INTE[1];
writeln( ' integer stored in array INTE
No.3 =',INTE[3]);
end.
sample2:
{two dimention}
var
inte:array[1..2,1..2] of integer;
begin
INTE[1,1]:=1;
inte[1,2]:=2;
inte[2,1]:=3;
inte[2,2]:=inte[1,1]+inte[1,2]+inte[2,1];
writeln( ' sum of integer stored in
3 array =',INTE[2,2]);
end.
notes:
In C,there are no string types allowed!!
so ,a array of char is used to
define a string type,
2.Build function:
.mathematical "function":
except uints ,and user define ,there are many BUILD
in function in PASCAL it self:
A. sqr(I) ,returns the square of integer/real
"I"
B. sqrt(I),returns the square root of real "I"
C. abs(I),returns the absolute value of real/integer
"I",like -1 become 1.
D. int(I) ,returns the integer part of real "I"
E.frac(I),returns the fractional part of real "I"
F.sin(I) and cos(I),return the sine/cosine ration
of radians real "I"
G.Ln(I),returns the natural logarithm of "I".
H.odd(I),returns a T/F value of show that the number
is ODD or EVEN.
I.round(I),return the closest integer value of I
(4 in 5 out)
J.trunc(I),return the integeral value of I (9 in
O out)
character mixing and string manipulate.
A.chr(I) return character in ASCII code "I"
B.ord(I) return ASCII code of character "I"
C.length(S) return the length of string "S"
D.concat(S1,S2,S3) return the concated (S1,S2,S3)
to other string;
E.copy(S,K,N)the string consisting of N characters
beginning at the Kth character of string Strg,
{"copy" part copy from book "element of pascal programming"}