Pascal Intro

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Introduction to Pascal

Programming
Key Points
• The same algorithms created in the previous lessons can be
implemented as a program.
• At the beginning course we learnt that a program is set of instructions
that tells the computer what to do.
• We have various application programs that we interact with daily such
as WhatsApp, FaceBook and Instagram.
• Last term we weren’t machine language (binary)
• Today we will learn how to create programs in high level language.
Programming Language
• This is an artificial language used to write instructions that can be
translated into machine language and then executed by a computer.

• Just as how people across the world speaks different language and sit
an exam in different language programs can be written in different
language.
Generation of languages
There are 5 generation of languages:
• First Generation Language (1GLs)
• Machine language
• Second Generation Language (2GLs)
• Assembly language
• Third Generation Language (3Gls)
• Python, Java
• Fourth Generation Language (4Gls)
• Sql
• Fifth Generation Language (5 Gls)
• Lisp
Generation of Languages

Low Level Programming Languages High Level Programming Languages


• First Generation Language • Third Generation Language
(1GLs) (3GLs)
• Machine language • Pascal, Python, Java
• Second Generation Language • Fourth Generation Language
(2GLs) (4GLs)
• Assembly language • Sql
• Fifth Generation Language (5
GLs)
• Lisp
Pascal
• For the purpose of this course we will program in a high language
called Pascal.
Basic Pascal Syntax
• To Display a statement
• WRITELN: is used to display a statement on a screen
• For example WRITELN (“Hello Students!”);
• For example WRITE(“Enter the price”);
• To input a value type
• READLN(Name of Variable);
• For Example:
• READLN(Price);
Basic Syntax Cont’d
• Begin with the keyword PROGRAM
• Give the program a name example: INVENTORY
• Replace your as with colons (:)
• Use VAR instead of Variable or Declare
• Use CONST instead of Constants
• All statements end with a semi-colon (;)
• All Prompt Statements should have quotations
• For Example: WRITELN( ‘Enter the quantity’)
• USE BEGIN instead of START
• USE END. Instead of STOP
• Provide a brief description of what the program is doing
• For Example: WRITELN(“This program will accept the price and quantity and print the total
price”)
Let’s Rewrite the Algorithm in Pascal
START
• Declare price as REAL
• Declare Quantity as INTEGER
• Declare Total Price as REAL

PRINT “Enter the quantity”


INPUT quantity
PRINT “Enter the price”
INPUT price
Total_Price=Price*Quantity
PRINT “The total price is”, Total_Price
STOP
Pascal Solution
Program Inventory (input, output);
VAR
price: REAL;
quantity: INTEGER;
Total_price:real;
BEGIN
WRITELN(‘This program will accept the price and quantity and find and print the total’);
WRITELN(‘Enter the price’);
READLN(price);
WRITELN(‘Enter the quantity’);
READLN (quantity);
Total_price::=Price*Quantity;
WRITELN(‘The total price is’, Total_price);
Readln();
END.
Activity 1
• Write a Pascal code that accepts 4 grades and print the average

You might also like