8 שיעור 


var NAME:string[20];         <-->  var NAME:packed array[0..20] of char;
    sentence:string[80];
    bigstring:string[255];

name:='Anyname';
writeln('The length of the name is ',ord(name[0]));

repeat
  readln(sentence);
  writeln(sentence)
until  sentence='I quit';            = <> < > <= >=

1) length(s)  <-->  ord(s[0])

2) name:=first + ' ' + last;
   name:=concat(first, ' ', last);

3) odstr:=copy(sentence,10,25);

4) loc:=pos('hello',sentence);

5) delete(name,10,4);

6) insert(' ',name,25);

program PARSE;
const space=' ';
var line,word:string[255];
    index,len:integer;
begin
  readln(line);
  while pos(space,line)=1 do   delete(line,1,1);
  len:=pos(space,line);
  if len=0
    then begin  word:=line; line:=''
         end
    else begin  word:=copy(line,1,len-1);
                delete(line,1,len)
         end
 end.

name:='Chana Webster';
middle:='Ann';
insert(middle, name, pos('Webster',name));
insert(' ',name,pos('Webster',name));
writeln('Your full name is ',name);

str(val,st)
val(st,val,index)

STRING FUNCTIONS         Turbo-Pascal            Vax-11 Pascal
----------------         ------------            -------------
                         1) n:=length(st)         n:=length(st)
                         2) +  concat               +
                         3) res:=copy(st,start,len)  res:=substr(st,start,len)
                         4) loc:=pos(pat,st)         loc:=index(st,pat)
                         5) delete(st,loc,len)
                         6) insert(str1,str2,loc)    pad(str1,ch,len)
                         7) str(val,st)
                         8) value(st,val,index)
                                             s:array varying[80] of char;
------------------------------------------------------------------------------ program example;
type smallstr=string[15];
var test:smallstr;
(*************************************************************************)
procedure showlength(st:smallstr);
begin
  writeln('Length of <',st,'> is ',length(st))
end;
(*************************************************************************)
begin       (* Main Program *)
  test:='hello there';
  showlength(test);
  test:='hi';
  showlength(test);
  test:='';
  showlength(test)
end.
----------------------------------------------------------------------------
program letter;
type bigstr=string[255];
     tokstr=string[80];
var line:bigstr;
(***************************************************************************)
procedure replace(var line:bigstr; token,sub:tokstr);
{  This procedure looks for 'token' in 'line', and replaces it with a new
      string, 'sub'.                                                     }
var indx, len:integer;
begin
  repeat
    indx:=pos(token, line);
    if indx>0 then begin
      delete(line, indx, length(token));
      insert(sub,line,indx)
    end
  until indx=0
end;
(**************************************************************************)
begin
  line:='And so, <title><last>, the entire <last> family';
  replace(line,'<title>','Dr.');
  replace(line,'<last>','Lewis');
  writeln(line)
end.








RECORDS
-------
type TAARICH=record
       day:1..30;
       month:(Nisan,Iyar,Sivan,Tamuz,Av,Elul,Tishrei,Cheshvan,Kislev,Tevet,
              Shvat,Adar);
       year:0..6000
     end;
var Hayom,Machar:taarich;

hayom.day:=8;
hayom.month:=Kislev;
hayom.year:=5750;
mahar:=hayom;
mahar.day:=mahar.day+1;

type shem=string[30];
     person=record
       fname,lname:shem;
       birthdate:taarich;
       sex:(male,female);
       marstatus:(single,married,divorced,widowed)
     end;
var me,you,newborn:person;
newborn.birthdate:=hayom;

type mishpacha=(aba,ima,yeled1,yeled2,yeled3);
var chisun:array[mishpacha] of taarich;

chisun[yeled3].day:=2;                with chisun[yeled3] do
chisun[yeled3].month:=Shvat;          begin    day:=2;
chisun[yeled3].year:=5743;                     month:=Shvat;
                                               year:=5743
                                      end;

program INSORT;
type rectype=record
       name:string[20];
       kita:char
     end;
var list:array[0..25] of rectype;
    j,achron:0..25;
    mispar:rectype;
begin
  for j:=1 to 25 do   readln(list[j].name, list[j].kita);
  list[0].name:='';
  for achron:=1 to 24 do
  begin   j:=achron;
    mispar:=list[achron+1];
    while mispar.name <list[j].name do
    begin   list[j+1]:=list[j];  j:=j-1  end;
    list[j+1]:=mispar
  end;
  for j:=1 to 25 do   writeln(list[j].name,list[j].kita)
end.