0% found this document useful (0 votes)
2 views

Colorful Pascal Programming

The document outlines a Pascal programming session led by teacher Kevan Sinanan, covering fundamental topics such as compiler setup, data types, control structures (if/else statements, loops), and basic programming constructs. It includes examples of Pascal code, flowcharts, and pseudocode, demonstrating how to write simple programs and handle common errors. Additionally, it discusses the distinction between low-level and high-level programming languages and provides resources for drawing flowcharts and compiling Pascal code online.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Colorful Pascal Programming

The document outlines a Pascal programming session led by teacher Kevan Sinanan, covering fundamental topics such as compiler setup, data types, control structures (if/else statements, loops), and basic programming constructs. It includes examples of Pascal code, flowcharts, and pseudocode, demonstrating how to write simple programs and handle common errors. Additionally, it discusses the distinction between low-level and high-level programming languages and provides resources for drawing flowcharts and compiling Pascal code online.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Pascal Programming Session 2

Teacher Name: Kevan Sinanan


Electrical and Computer Engineer
Studied at UWI St. Augustine Campus
Pascal Programming – Topics
Setting up complier Operations ( + - x / )
Initialization If / else statements
While loops
Input output Writeln readln
For loops
Data types Common errors , comments
Constants
Variables
Pascal Compiler
https://www.tutorialspoint.com/compile_pascal_online.php
Why is Programming Cool ?
Why is Programming Cool ?
Create Phone Apps

Video Games

Perform Calculations

Make Spacecrafts
Which of these have Computer Program?

Smart TV
Playstation Gaming Console

Mars Rover
Digital Car Radio

Saw
Which of these have Computer Program?

Smart TV
Playstation Gaming Console

Mars Rover
Digital Car Radio

Saw
If it has a

CPU
Then it uses a software program
What is needed to write a program?
Code
Compiler
Computer
How to write a program?
Code Algorithm Instructions / Programming Language
Compiler Translates the code
Computer Performs the instructions in its language
CODE Programming Language
Low Level Languages High Level Languages
Machines friendly Human Friendly
Machine dependent Computer independent
Hard to write Easy to write
Fast execution Longer to execute
Converted into machine level language
Low Level Languages

Machine Friendly
Machine Dependent
Hard to write
Fast execution
High Level Languages
Human Friendly
Computer independent
Converted into machine level language
Easy to write
Longer to execute
Programming Building Blocks Simple Sequence
PROGRAM NAME
VARIABLES
START
PRINT
READ
STOP
Programming Building Blocks Simple Sequence
PROGRAM NAME Labels the name of the program
VARIABLES declare inputs and outputs types
START identifies the beginning of program
PRINT Display outputs
READ Receive inputs
STOP end of program
Programming Example Pseudocode
START
name=’ABC’
age= 0
PRINT “What is your name?”
READ name
PRINT “How old are you?”
READ age
PRINT “Hello”, name , “you are ”, age , “years old”
STOP
Programming FLOWCHART

Oval (Terminal symbol) Diamond (Decision symbol)

Rectangle (Process symbol) Parallelogram

(Input/Output symbol)

Arrow (Arrow Symbol) Circle (Connector Symbol)


Programming FLOWCHART
Diamond (Decision symbol)
START No Age is a number? YES
Oval (Terminal symbol)
STOP Question and answer

name=’ABC’ Rectangle (Process symbol) Parallelogram


PRINT “What is
age= 0
your name?”
(Input/Output symbol)
READ name

Arrow (Arrow Symbol)


Circle (Connector Symbol)
Software you can use draw Flowcharts
https://app.diagrams.net/
Our first Pascal Code
https://www.tutorialspoint.com/compile_pascal_online.php

Program Nameage(output);
var
name: string;
age: integer;

begin
name:= 'ABC';
age:=0;
writeln('What is your name?');
readln(name);
writeln('What is your age');
readln(age);
writeln('Hello! ', name, ' Your age is ', age );
end.
Programming Pascal Code
Programming Pascal Code
Program Name, no spaces
Programming Pascal Code
Declaring variables
variables. Name is String
variables. Age is Integer, no letters
Programming Pascal Code

Start
Programming Pascal Code

Initialize Variable , name is ABC


Initialize Variable, age is 0
Programming Pascal Code
Programming Pascal Code
Programming Pascal Code
Program Name
Declaring variables
variables. Name is String
variables. Age is Interger

Start
Initialize Variable
Initialize Variable

Output
Input and store
Output
Input
Output
Stop
Programming Pascal Code error
Can you spot the Error?
Can you spot the Error?

Semicolon ; is missing
Can you spot the Error?
Can you spot the Error?

Input is not declared , incorrect spelling


Can you spot the 4 errors?
Can you spot the 4 errors?
Space in name

Space in readln, It is one word


Space in writeln, It is one word

end. The period is missing


Common Syntax errors

Semicolons ;
End. no fullstop at the end
Space in names read ln , program name
Programming Pascal Code Comments

// double back slashes for comments

{
Comments in multi lines

}
Programming 2nd Example Enter name and calculate age
Program Nameage(output);
var
name: string;
age , newage: integer;

begin
name:= 'ABC';
age:=0;
newage:=0;
writeln('What is your name?');
readln(name);
writeln('What year were you born?');
readln(age);
newage:= 2024 - age;
writeln('Hello! ', name, ' Your age is ', newage );
end.
Programming 2nd Example Enter name and calculate age
Data Types or Variables or Var
Visit : https://www.tutorialspoint.com/pascal/pascal_variable_types.htm

Character

Typically a single octet (one byte). This is an integer type.

Integer

The most natural size of integer for the machine.

Real

A single-precision floating point value.

String

Stores an array of characters.


Pseudo Code
If Then ELSE Statements Conditional branches Decisions

IF condition THEN
action(s)
ELSE
action(s)
ENDIF
Programming FLOWCHART
If Then ELSE Statements ConditionalDiamond
branches Decisions
(Decision symbol)

THEN
IF

Condition

ELSE
Programming FLOWCHART
If Then ELSE Statements Conditional branches Decisions
Example
Write a program to calculate if a student passes his
exam. If his score is above 95 then he passes
Note you must do:
Pseudo code
Flowchart
Pascal code
Example
Write a program to calculate if a student passes his exam. If his score is above 95 then he passes

Pseudo code
START
score= 0
Print “Enter your Score”
READ score

If score is > 95 then


Print “You Passed”
Else
Print “You Failed”
ENDIF
STOP
Example
Write a program to calculate if a student passes his exam. If his score is above 95 then he passes

FLOWCHART
Example
Write a program to calculate if a student passes his exam. If his score is above 95 then he passes
Version 1

Program StudentPass(output);
var
score: integer;
begin
writeln('Please enter your score');
readln(score);
if score >90 then
writeln(' You have passed')
else
writeln(' you did no pass');

end.
Version 2
Program StudentPass(output);
var
score: integer;
begin
writeln('Please enter your score');
readln(score);
if score >90 then begin
writeln(' You have passed');
end
else begin
writeln(' you did no pass');
end
end.
Loops

FOR

WHILE
Loops

FOR
Finite
Executes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.

WHILE
infinite
Repeats a statement or group of statements while a given condition is true.
It tests the condition before executing the loop body.
Loops

FOR
Program StudentPass(output);
var
i, passed, score: integer;
begin
score:=0;
i:=0;
passed:=0;
for i:=1 to 4 DO
begin
writeln('Please enter your score');
readln(score);
if score >90 then
writeln(' You have passed')
else
writeln(' you did not pass')

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy