(* Techniques : This program demonstrates the use of CASE for slecting choices, calling procedures to show the use of string functions COPY, ORD, CHR and procedure STR. *) {*Winnie Leung F.4CA (22) *} program StringFunction; uses wincrt; var i:integer; choice,ans:char; procedure f_copy; var strg:string[5]; begin strg:='JAMES'; writeln('This procedure uses COPY function to show the characters of a word'); writeln('seperated from the right to the left.'); writeln('The original string : ',strg); writeln('The characters seperated from the right to the left : '); for i:=length(strg) downto 1 do writeln(copy(strg,i,1)) end; procedure f_ord; begin writeln; writeln('This procedure uses ORD function to print out the ASCII codes of P,Q and R.'); writeln('ASCII of P is ',ord('P')); writeln('ASCII of Q is ',ord('Q')); writeln('ASCII of R is ',ord('R')) end; procedure f_chr; begin writeln; writeln('This procedure uses CHR function to print out the characters of A,B and C.'); writeln('The character with ASCII of 65 is ',chr(65)); writeln('The character with ASCII of 66 is ',chr(66)); writeln('The character with ASCII of 67 is ',chr(67)) end; procedure p_str; var n:integer; n_strg:string[4]; digit:string; begin writeln; writeln('This procedure uses STR procedure to show a number converted to a string.'); writeln('Then print out each digit from the left to the right.'); writeln('Enter a number not more than 4 digits.'); readln(n); str(n,n_strg); for i:=1 to length(n_strg) do begin write('Character ',i); digit:=copy(n_strg,i,1); writeln(' : ',digit) end end; (*MAIN PROGRAM*) begin writeln('This program demonstrates the use string functions by calling procedures.'); repeat writeln; writeln('Press A for calling the demo procedure for COPY function'); writeln('Press B for calling the demo procedure for ORD function'); writeln('Press C for calling the demo procedure for CHR function'); writeln('Press D for calling the demo procedure for STR procedure'); readln(choice); case choice of 'A': f_copy; 'B': f_ord; 'C': f_chr; 'D': p_str; end; write('Continue (Y/N) ?'); readln(ans) until ans='N'; writeln('Good Bye') end.