0% found this document useful (0 votes)
3 views5 pages

Pascal Programming

Uploaded by

surencoceynomin
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)
3 views5 pages

Pascal Programming

Uploaded by

surencoceynomin
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

PASCAL PROGRAMMING

Problem Solving and Algorithms

Before writing any code, it is essential to understand and plan a solution for a
problem.

• The raw materials used to solve a problem are known as the input.
• The result obtained after solving a problem is known as the output.
• Converting input to output is called the process.
• An algorithm is a step-by-step procedure for solving a problem.
• When a problem has multiple solutions, these are called alternative
solutions, and the best one must be selected based on efficiency.

Control Structures

Algorithms use three primary control structures to dictate the flow of a program:

• Sequence: Steps are carried out in a strict order from beginning to end.
• Selection: A specific step or set of steps is executed based on whether a
condition is satisfied or not.
• Repetition: One or several steps are repeated until a specific condition is
met.

Representing Algorithms

Algorithms can be represented using visual diagrams or plain text to make them
easier to understand before actual coding begins.

• Pseudocodes: An algorithm presented in simple English terms. Pseudocodes


are independent of any computer language and can easily be converted into
programming instructions.
• Flowcharts: Visual tools used to present how an algorithm is built step by
step.
Standard Flowchart Symbols

Symbol Shape Function

Oval Start or end

Parallelogram Input or output


Rectangle Process
Diamond Decision
Arrow Flow direction
Circle Connector

Pascal Programming Basics

Identifiers and Reserved Words

• An identifier is a term used to represent a variable, constant, or a program.


• Identifiers must start with an English letter.
• After the first letter, identifiers can contain letters, numbers, or underscores.
• Identifiers are not case sensitive and cannot contain spaces or special
characters other than an underscore.
• Reserved words are terms predefined in the Pascal language (like BEGIN,
END, IF, WHILE) and cannot be used as identifiers.

Variables and Constants

• Variables: Identifiers that can change their assigned values while the
program is executed. They are declared using the var keyword.
• Constants: Identifiers that do not change their values while the program is
executed. They are declared using the const keyword.

Standard Data Types

When a program is executed, the space needed in the computer's memory is


defined by the data type.

Data Type Description


Integer Plus or minus whole numbers

Real Plus or minus decimal numbers


Boolean True or False
Char Any single character on the keyboard
String Any sequence of characters

Note: Character and string values must be enclosed in single quotation marks.

Operators

Operators are required to perform calculations, compare values, and evaluate


logical expressions.

Category Operators Priority


Level

Logical (Unary) NOT 1 (Highest)

Arithmetic (Mult/Div) *, /, DIV (division of round numbers), 2


& Logical MOD (remainder), AND
Arithmetic (Add/Sub) +, -, OR 3
& Logical
Comparison =, < > (not equal), <, <=, >, >= 4 (Lowest)

Control Statements in Pascal

1. Selection Statements

• IF...THEN: Executes a statement only if the condition is satisfied.


• IF...THEN...ELSE: Executes the first statement if the condition is satisfied;
if not, it executes the alternative statement.
• Nested IF: Used when there are multiple sequential conditions to check.
• CASE: A simpler structure to use instead of nested IFs when checking a
single variable against multiple potential conditions.

2. Repetition Statements (Loops)


• FOR-DO: Used when the exact number of repetitions is known in advance.
It can count up (TO) or count down (DOWNTO).
• WHILE-DO: Checks the condition at the beginning of the loop. The
statements inside are only executed if the condition is true.
• REPEAT-UNTIL: The condition is checked after the statements execute at
least once. The loop stops when the condition becomes true.

Advanced Pascal Structures

Arrays

An array is a data structure used to save multiple data items of the same type in
sequential memory spaces under a single variable identifier name.

• Elements are positioned adjacently.


• Any element can be accessed randomly using an index number enclosed in
square brackets.

Sub-programs

As programs become complex, breaking them into sub-programs makes them


easier to read and maintain.

• Functions: Sub-programs that return an output back to the main program.


• Procedures: Sub-programs that do not return an output back to the main
program.
• Both must be declared before the main program block begins.

Evolution of Programming Languages

A programming language is needed to provide instructions to a computer to


perform tasks.

Low-Level vs. High-Level Languages


• Machine Language (Low-Level): Uses binary numbers (0s and 1s) and is
directly understood by the processor. It is fast but heavily machine-
dependent and difficult for humans to understand.
• Assembly Language (Low-Level): Uses simple symbols instead of binary
code, but still relies on an assembler to translate it and is machine-
dependent.
• High-Level Languages: Languages like Pascal, C, and FORTRAN use
simple English words, making them easier to understand. They do not
depend on the specific machine hardware but require translation into
machine code before executing.

Language Translators

• Interpreter: Translates and executes high-level statements into machine


language one by one. It will stop running if it hits a syntax error.
• Compiler: Translates the entire high-level program into machine language
as a whole before executing it. Once compiled, the program can be run
multiple times without needing to be re-translated.

Programming Paradigms

A paradigm is a specific approach to developing a software solution.

• Procedural Paradigm: Uses a well-structured set of steps and procedures


(algorithms) stating how a problem should be solved.
• Declarative Paradigm: Focuses on explaining what outcome is wanted
rather than detailing the specific control flow or execution steps.
• Object-Oriented Paradigm: Based on objects that encapsulate both data
(attributes/properties) and code (methods/procedures).

You might also like