All pastes #180327 Raw Edit

Unnamed

public text v1 · immutable
#180327 ·published 2006-09-23 01:21 UTC
rendered paste body
{ May 2, 1995 }
{ String management procedures }

program Strings;

uses crt;

{ ------------------------------------------------------------------------ }

procedure Intro;
begin { procedure Intro }
      writeln('Welcome!');
      writeln;
      writeln('This program uses several string management functions to');
      writeln('demonstrate how strings can be manipulated in Turbo Pascal.');
      writeln('There are three demonstrations.  Follow the instructions for');
      writeln('each.');
      writeln;
end; { procedure Intro }

{ ------------------------------------------------------------------------ }

procedure Average;

var
   count, code : integer;
   sum, average : real;
   numbers : string;
   pause : char;

begin { procedure Average }
      clrscr;
      writeln('This procedure calculates the avgerages of inputted numbers.');
      writeln;
      writeln('Enter as many numbers as you wish.');
      writeln('Enter "done" on a blank line to quit.');
      writeln;
      sum := 0;
      count := 0;
      code := 0;
      repeat
            write('Enter a number:  ');
            readln( numbers );
            if numbers <> 'done' then
               begin
                    count := count + 1;
                    val ( numbers, average, code );
                    sum := sum + average;
               end;
      until numbers = 'done';
      average := sum / count;
      writeln;
      writeln;
      write('The average is ');
      writeln( average:1:2, '.' );
      writeln;
      writeln('Press any key to continue.');
      pause := readkey;
end; { procedure Average }

{ ------------------------------------------------------------------------ }

procedure Sum;

var
   Sum, Number, count, code : integer;
   StrSum, numString, StringSum : string;
   pause : char;

begin { procedure Sum }
      clrscr;
      writeln('This procedure calculates the sum of inputted numbers.');
      writeln;
      writeln('Enter as many numbers as you wish, as one continuous integer.');
      writeln;
      sum := 0;
      count := 0;
      code := 0;
      write('Enter a number:  ');
      readln( number );
      str ( number, numString );
      for count := 1 to length ( numString ) do
          begin
               Strsum := numString[count];
               val ( StrSum, Number, code );
               Sum := Sum + Number;
          end;
      writeln;
      writeln;
      write('The sum is ');
      writeln( sum, '.' );
      writeln;
      writeln('Press any key to continue.');
      pause := readkey;
end; { procedure Sum }

{ ------------------------------------------------------------------------ }

procedure StringThing;

var
   input : string;
   count : integer;
   pause : char;

begin { procedure StringThing }
      clrscr;
      writeln('This procedure does a neat little thing with a string.  It is');
      writeln('rather hard to explain the effect of this procedure, so please');
      writeln('just try it out to see what it does for yourself.');
      writeln;
      writeln;
      write('Please enter a string:  ');
      readln( input );
      for count := 1 to length ( input ) do
          begin { for count := 1 to length ( input ) do }
                writeln( copy ( input, 1, count ) );
          end; { for count := 1 to length ( input ) do }
          writeln;
          writeln;
          writeln('--');
          writeln('Thank you for using this software.');
          writeln;
          writeln('Press any key to quit.');
          pause := readkey;
end; { procedure StringThing }

{ ------------------------------------------------------------------------ }

begin { Main Program }
      Intro;
      Average;
      Sum;
      StringThing;
end. { Main Program }