Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
3K views

Pascal Intro

The program declares variables to store 4 grades as integers, calculates the total of the grades, calculates the average by dividing the total by 4, and prints the average. Program GradeAverage(input, output); VAR grade1, grade2, grade3, grade4: INTEGER; total, average: REAL; BEGIN WRITE('Enter grade 1: '); READLN(grade1); WRITE('Enter grade 2: '); READLN(grade2); WRITE('Enter grade 3: '); READLN(grade3); WRITE('Enter grade 4: '); READLN

Uploaded by

api-297910907
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views

Pascal Intro

The program declares variables to store 4 grades as integers, calculates the total of the grades, calculates the average by dividing the total by 4, and prints the average. Program GradeAverage(input, output); VAR grade1, grade2, grade3, grade4: INTEGER; total, average: REAL; BEGIN WRITE('Enter grade 1: '); READLN(grade1); WRITE('Enter grade 2: '); READLN(grade2); WRITE('Enter grade 3: '); READLN(grade3); WRITE('Enter grade 4: '); READLN

Uploaded by

api-297910907
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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