Thursday, 25 April 2013

Basic Pascal Structure

program program_name;
Uses WinCRT;
Var
{Variable declaration}
Begin
{Program instructions}
End.
There a reserved words in pascal. These reserved words are explain in the table below:
Reserve Word
Definition


Program
The first word in a pascal prgoram. It is then followed by the program name. For example:
Program program_name;
Uses
It allows the program to do certain operations. For example
Uses WinCRT;
This allows the program to display to the screen and accept values from the keyboard
Type
States the area for defining subranged data types.
Const
States the area for declaration of constants.
Var
States the area for declaration of variables.
Begin
Indicates the beginning of a programming instructions.
End.
The last word in a pascal program. This word pronounciates the end of the pascal program.

Variables and constants.

Variables and constants are like cups in memory. They hold the designated type of data desired by the programmer. Variables allow the option for its content to vary. Variables are like a cup that one can use to pour in juice at one time, water at another time and wine another. While constants are are set and can not change its content. Like a cup that its content has been insert then sealed, it content stay permanent and can not change.

Declaration of Variables in Pascal

In pascal variables can not just be used at will. First these variables need to be created before they are uses. This creation of these cups in memory is called the declaration of variables process. To declare these variables we follow the following syntax.
Var
variable_name:data_type;
length:integer;
width:integer;
price:real;

Declaration of Constants in Pascal

Just like Variables constants are need to be declared. The syntax is as followed:
Const
constant_name=Value;
VAT=0.17;
Message='Fail';

Input and output in Pascal

In pascal we can accept values from the keyboard and display values to the screen. To do this we use the commands read and readln for input. While for output we can use the commands write and writeln.The syntax is as followed:

writeln('Enter a number');
This will display the message Enter a number to the screen

readln(num);
This will accept a value from the keyboard and store it in the variable num.

writeln('The number you entered is ',num);
This will display to the screen The number you entered is 7. It will display the message followed by the content that is in the variable num.