Advanced Pascal Programming Language Problems

© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved


     Instructions:   Review the following program and see if you can 
                     predict the outcome by completing a "pencil 
                     trace" of the code.  

                     Program output is provided at the end of this 
                     page.

     Compiler:       The program was prepared using Standard Pascal 
                     on a UNIX-based host computer.


% cat PASCAL/advanced_pencil-06.p
{ Advanced Pascal Programming Language Exercises
  Dr. Thomas W. MacFarland
  advanced_pencil-06.p
}

{ The purpose of this program is to:

  1.  Demonstrate the four types of variables:  integer, real,
      character, and Boolean.

  2.  Demonstrate how integer and real variables are used in
      some mathematical operations.

  3.  Demonstrate simple functions used in Standard Pascal.
}

program Demonstrate_Multiple_Types_of_Variable_Types;


var A,B: integer;
    C,D: real;
    E:   char;
    F:   boolean;

begin
   A := 99;
   B := 84;
   C := B;           
   D := 456.789;
   E := chr(A);      
   F := true; 
   writeln('**********************************');
   writeln('A = ',A:12,  '  B = ',B:12);
   writeln('C = ',C:12:2,'  D = ',D:12:2);
   writeln('E = ',E:12,  '  F = ',F:12);
   writeln('**********************************');

   A := round(C);     
   B := trunc(D);   
   C := sqrt(D); 
   D := sqr(A);
   E := chr(B);      
   F := false; 
   writeln('**********************************');
   writeln('A = ',A:12,  '  B = ',B:12);
   writeln('C = ',C:12:2,'  D = ',D:12:2);
   writeln('E = ',E:12,  '  F = ',F:12);
   writeln('**********************************');

   A := ord(E);   
   B := succ(A);
   C := sqr(D); 
   D := sqrt(A);
   E := chr(A);      
   F := true; 
   writeln('**********************************');
   writeln('A = ',A:12,  '  B = ',B:12);
   writeln('C = ',C:12:2,'  D = ',D:12:2);
   writeln('E = ',E:12,  '  F = ',F:12);
   writeln('**********************************');

end.  {advanced_pencil-06.p}

%  pc PASCAL/advanced_pencil-06.p
%  a.out
**********************************
A =           99  B =           84
C =        84.00  D =       456.79
E =            c  F =         true
**********************************
**********************************
A =           84  B =          456
C =        21.37  D =      7056.00
E =            H  F =        false
**********************************
**********************************
A =          200  B =          201
C =  49787136.00  D =        14.14
E =            H  F =         true
**********************************

Please send comments or suggestions to Dr. Thomas W. MacFarland

There have been [an error occurred while processing this directive] visitors to this page since February 1, 1999.