ffcurrency
formats the value with the currency included
ffexponent
formats the value in scientific notain
fffixed
formats the value with the number of decimals as specified
string
address:=inputbox(‘address’,’enter the address’,’ ‘);
example using ffcurrency
redoutput.lines.add(‘final amount’+#9+floattostr(rfinalamount,ffsurrency,6,2));
ffgeneral
general number format. Includes decima;s oly when required
ffnumber
corresponds to fffixed , but uses thousands separator
integer
icount:= strtoint(iputbox(‘amount’,’enter the amount’,’ ‘);
real
rsales:=strtoint(inputbox(‘sales’, ‘please enter the sales figure’ ,’ ‘));
char
cclass:= inputbox(‘class’ , ‘ please enter the class ‘ , ‘ ‘)[1];
general structure of the if statement
if <conditions> then
begin</conditions>
<statements> ;
end
else
begin
<statements> ;
end;
</statements></statements>
case statement example
if imark>=80 then
csymbol:=’A’;
else
if imark>=70 then
csymbol:=’B’’;
else
if imark>=80 then
csymbol:=’A’;
the while loop
var
isum , inumber :integer;
begin
isum:= 0;
inumber:= 1;
while inumber <10 do
begin
isum:=isum +inumber ;
inumber := inumber +2 ;
end ;
redoutput.lines.add(inttostr(isum));
declaring an array
var
frmarray:tfrmarrays;
rrnumber:array[1..100] of integer;
icount: integer ;
load numbers from a textfile into an array
var
tf:textfile;
stemp: string ;
begin
icount := 0;
assignfile(tf, ‘numbers.txt’);
reset (tf);
while not eof(tf) do
begin icount:= icount+1 ;
readln (tf,stemp );
arrnumbers [icount]:= strtoint(stemp ) ; end ;
closefile (tf) ;
end ;
remove numbers that repeat in an array
var
ioutbound ,iinbound,ireplace : integer;
begin
for ioutbound := 1 to icount -1 do
begin
for iinbound:= ioutbound +1 to icount do
begin
if arrnumbers [ioutbound]= arrnumbers [iinbound ]
then
begin
for ireplace :=ioutbound to icount do
begin
arrnumbers[ireplace]:= arrnumbers [ireplace+1];
end;
end;
end;
end;
show numbers from an array in a richedit
var
iforcount : integer;
begin
redoutput.clear ;
for iforcount:= 1 t icount do
begin
redoutput.lines.add(inttoatr(arrnumbers[iforcount]));
find number (Item ) in an array
var
iforcount :iteger;
isearch:integer;
begin
isearch:= strtoint(edtfind.text);
for iforcount :=1 to icount do
begin
if isearch := arrnumbers[foricout] then
begin
showmessage (‘nummber found at :’ + inttostr(iforcount));
exit;
end;
end;
end;
binary search in an array
var
iforcount :integer;
isearch , ilowbound ,iupbound , imiddle ,iposition : integer ;
bfound : boolean ;
begin
bfound := false ;
ilowbound :=1;
iupbound:=icount;
ipostion:= 0;
isearch:= strtoint(edtfind.text);
while (ilowbound<= iupbound) and ( bfound =false )
do
begin
imiddles :+ (ilowbound +iupbound ) di 2 ;
if isearch =arrnumber [imiddles ] then
begin
iposition:= imiddle;
bfound := true ;
end
else
if isearch > arrnumbers [imiddle ] then
ilowbound := imiddle+1 else
iupbound :=imiddle -1 ;
end ;
if bfound =true then
begin
showmeassage (‘number found at:’+ inttostr(ipostion ) );
end
else
begin
showmessage (‘number not found);
end
end ;
selection sort
var
icountout , icountcomp, itemp :integer;
begin
for icountout :=1 to icount do
begin
for icountcomp:= icountout to icount do
begin
if arrnumbers [icountout]> arrnumbers [icountcomp]
then
begin
itemp:= arrnumbers [icountout];
arrnumbers[icountout]:=arrnumbers [icountcomp];
arrnumbers [icountcomp]:=itemp;
end;
end;
end;
end;
bubble sort
var
itemp, icounter : integer;
bswap :boolean ;
begin
bswap:= true;
for icounter:= 1 to icount -1 do
begin
if arrnumbers [icounter]>arrnumbers [icounter+1] then
begin
itemp:= arrnumbers [icounter];
arrnumbers