pascal cheat sheett code example

Example 1: pascal cheat sheett

type
   Rptr = ^real;
   Cptr = ^char;
   Bptr = ^ Boolean;
   Aptr = ^array[1..5] of real;
   date-ptr = ^ date;
      Date = record
         Day: 1..31;
         Month: 1..12;
         Year: 1900..3000;
      End;
var
   a, b : Rptr;
   d: date-ptr;

Example 2: pascal cheat sheett

var
choice: boolean;

Example 3: pascal cheat sheett

Sr.No	Control Statement & Description
1	break statement
Terminates the loop or case statement and transfers execution to the statement immediately following the loop or case statement.

2	continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

3	goto statement
Transfers control to the labeled statement. Though it is not advised to use goto statement in your program.

Example 4: pascal cheat sheett

VELOCITY_LIGHT = 3.0E=10;
PIE = 3.141592;
NAME = 'Stuart Little';
CHOICE = yes;
OPERATOR = '+';

Example 5: pascal cheat sheett

program addFiledata;
const
   MAX = 4;
type
   raindata = file of real;

var
   rainfile: raindata;
   filename: string;
procedure writedata(var f: raindata);

var
   data: real;
   i: integer;

begin
   rewrite(f, sizeof(data));
   for i:=1 to MAX do
   
   begin
      writeln('Enter rainfall data: ');
      readln(data);
      write(f, data);
   end;
   
   close(f);
end;

procedure computeAverage(var x: raindata);
var
   d, sum: real;
   average: real;

begin
   reset(x);
   sum:= 0.0;
   while not eof(x) do
   
   begin
      read(x, d);
      sum := sum + d;
   end;
   
   average := sum/MAX;
   close(x);
   writeln('Average Rainfall: ', average:7:2);
end;

begin
   writeln('Enter the File Name: ');
   readln(filename);
   assign(rainfile, filename);
   writedata(rainfile);
   computeAverage(rainfile);
end.

Example 6: pascal cheat sheett

const
identifier = constant_value;

Example 7: pascal cheat sheett

var
subrange-name : lowerlim ... uperlim;

Example 8: pascal cheat sheett

0 1 1 2	3 5 8 13 21 34

Example 9: pascal cheat sheett

program exRecursion;
var
   num, f: integer;
function fact(x: integer): integer; (* calculates factorial of x - x! *)

begin
   if x=0 then
      fact := 1
   else
      fact := x * fact(x-1); (* recursive call *)
end; { end of function fact}

begin
   writeln(' Enter a number: ');
   readln(num);
   f := fact(num);
   
   writeln(' Factorial ', num, ' is: ' , f);
end.

Example 10: pascal cheat sheett

Number is: 100
iptr points to a value: 100
Number is: 200
iptr points to a value: 200
45504

Tags:

Misc Example