Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Pascal The Basics of Program writing.

Similar presentations


Presentation on theme: "Introduction to Pascal The Basics of Program writing."— Presentation transcript:

1 Introduction to Pascal The Basics of Program writing.

2 Pascal Format Program ; const ; var begin end. HEADER VARIABLE DECLARATION PROGRAM BODY CONSTANT DECLARATION

3 Constants and Variables Identifier – The name that identifies a variable or constant Constant – a value that is stored in memory and cannot be changed. Eg. Pi = 3.14 Variable – A value that is stored in memory and can be changed. Eg. x,a,b,y…….

4 Variable Types Integer – positive and negative numbers which do not have a decimal point. Real – positive and negative numbers that my have a decimal point Char – a single character (letter, digit or symbol) String – a group of characters Boolean – either true or false

5 Declaring Variables var gender: char; num1, num2, num3: integer; product: real THREE VARIABLES OF THE SAME TYPE CAN BE SEPARATED BY A COMMA

6 Declaring Constants const pi = 3.142; VAT = 0.15; Gravity = 9.81;

7 Basic Commands Write – writes the command on the same line Writeln – writes the command and goes to the next line Read – reads the input Realn – reads the input and then goes to the next line.

8 Write commands Write(‘ hello world’); Writeln (‘hello world’); Hello World DISPLAYS ‘HELLO WORLD’ IN THE SAME LINE Hello World _ DISPLAYS ‘HELLO WORLD’ AND GOES TO THE NEXT LINE

9 Read Commands Read(num1) This will read the input from the user of the program and store the value in num1 Readln(num1) This will read the input from the user and store the value in num1 and go to the next line. It is also used to pause at the end of a program until the user presses enter.

10 Assignments The value of a variable can be changed by doing an assignment statement. It is done by using a colon and equal sign. := eg. Age := 15 cost := 65 Count := count + 1

11 Simple Progams Program HelloWorld; Begin Write(‘Hello World’); Readln; End. This program writes Hello World and then waits for the user to press enter to exit the program.

12 Simple Programs program Hello; begin Writeln('Hello'); Write('world'); Readln; end. This program writes ‘Hello’ in one line then goes to the other, then it prints ‘World’ and waits for the user to press enter.

13 Simple Programs Program Addition; Var a:integer; Begin Writeln('The sum of 6 and 4 is:'); a := 6 + 4; write(a); readln; End. This declares ‘a’ as an integer. It then adds two numbers and assigns the result to ‘a’.

14 Simple Programs Program Multiplication; Var a: integer; Begin Writeln ('This will find the product of 6 and 4'); a := 6*4 ; writeln ('Press enter to view the result'); readln; write(a); readln; End. This declares ‘a’ as an integer. It then multiplies two numbers and assigns the result to ‘a’. Then displays ‘a’

15 Simple Programs Program addition; Var a:integer; b:integer; c: integer; Begin writeln(‘Enter first number’); read(a); writeln(Enter second number’); read(b); writeln(‘Your numbers are: ‘,a,b); c:= a + b writeln(‘the sum of your numbers is:’); write(c); readln; End. This declares ‘a’ ‘b’ and ‘c’ as integers. It then adds ‘a’ to ‘b’ and assigns the result to ‘c’. Then displays ‘c’


Download ppt "Introduction to Pascal The Basics of Program writing."

Similar presentations


Ads by Google