PASCAL. PASCAL, like BASIC, is a computer language. However, PASCAL, unlike BASIC, is a Blocked Structured Language (BASIC is known as unstructured).

Similar documents
Enumerated Types. Mr. Dave Clausen La Cañada High School

Lecture 3. The syntax for accessing a struct member is

Other conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen

AIMMS Function Reference - Date Time Related Identifiers

Introduction to Computers and Programming

Armstrong State University Engineering Studies MATLAB Marina Switch-Case Statements Primer

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

car object properties data red travels at 50 mph actions functions containing programming statements Program Program variables functions

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

BUP2 5/2 12/4/07 12:49 AM Page 1. Introduction

More non-primitive types Lesson 06

Arrays (Lists) # or, = ("first string", "2nd string", 123);

Motivation. Each distinct type needs its own I/O library INTEGER FLOAT CHARACTER BOOLEAN. Using pure numbers, we can write nonsense:

Arrays III and Enumerated Types

Maintaining the Central Management System Database

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

Data Types and Variables in C language

Chapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction

BASIC ELEMENTS OF A COMPUTER PROGRAM

Introduction to Python

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic:

Daily Math Week 8 ( ) Mon. October 7, 2013 Tues. October 8, 2013 Wed. October 9, 2013 Thurs. October 10, 2013 Fri.

Chapter 6. Data Types

Objectives. Describe ways to create constants const readonly enum

Pre-Calculus Advanced. Chapter 10 Part 2. Period 8

EECS402 Lecture 24. Something New (Sort Of) Intro To Function Pointers

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

Using Variables to Write Pattern Rules

Industrial Programming

Arrays. Array Basics. Chapter 8 Spring 2017, CSUS. Chapter 8.1

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

Private Swimming Lessons

Scheduling. Scheduling Tasks At Creation Time CHAPTER

CSCE 314 Programming Languages

Total Market Demand Wed Jul 26 Thu Jul 27 Fri Jul 28 Sat Jul 29 Sun Jul 30 Mon Jul 31 Tue Aug 01

Daily Math Week 10 ( ) Mon. October 21, 2013 Tues. October 22, 2013 Wed. October 23, 2013 Thurs. October 24, 2013 Fri.

Basic Elements of C. Staff Incharge: S.Sasirekha

SOUTH DAKOTA BOARD OF REGENTS. Board Work ******************************************************************************

BLM2031 Structured Programming. Zeyneb KURT

MyOwnDeliveries. a Magento module. User manual

Chapter 3. Ch 1 Introduction to Computers and Java. Selections

Computing is about Data Processing (or "number crunching") Object Oriented Programming is about Cooperating Objects

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

Conditional Formatting

Algorithm For Scheduling Around Weekends And Holidays

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

CSCI 150: Exam 1 Practice

Study Guide and Review - Rational Numbers

Preview from Notesale.co.uk Page 6 of 52

Integer Data Types. Data Type. Data Types. int, short int, long int

Chapter 2: Objects and Primitive Data

CSCI 150: Exam 1 Practice

COP4020 Programming Assignment 1 - Spring 2011

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

SF - Math Steps, MI test, other review MATH INVENTORY. Week 3-8/28-9/1 - Standards: Lesson Objective/Plan Resources Section in Book Homework

DigiPen Institute of Technology

Object-Oriented Principles and Practice / C++

Programming in Haskell Aug-Nov 2015

D. 90% 2. You need of a can of paint to paint one bench. How many cans would you need to paint 8 benches of equal size?

Problem Solving. Problem Solving Concept for Computer Science

Seventh Grade Spiraling Review Week 1 of First Six Weeks

if Statement Numeric Rela5onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

Assessment - Unit 3 lessons 16-21

Lecture Notes on Programming Languages

if Statement Numeric Rela7onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

TYPES, VALUES AND DECLARATIONS

CSCI 1061U Programming Workshop 2. C++ Basics

12 CREATING NEW TYPES

Datatypes, Variables, and Operations

CSE 452: Programming Languages. Where are we? Types: Intuitive Perspective. Data Types. High-level Programming Languages.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CS349/SE382 A1 C Programming Tutorial

Boolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;

CSCI 150: Exam 1 Practice

Chapter. Solving Problems that Require Decisions. Objectives: At the end of the chapter students should be able to:

UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013

Chapter 21: Introduction to C Programming Language

CSCI312 Principles of Programming Languages!

DECISION CONTROL AND LOOPING STATEMENTS

Values, types and variables

DATA AND ABSTRACTION. Today you will learn : How to work with variables How to break a program down Good program design

SOUTH DAKOTA BOARD OF REGENTS. Board Work ******************************************************************************

Part No. P CallPilot. Programming Record

Payflow Implementer's Guide FAQs

PROGRAMMAZIONE I A.A. 2017/2018

OPERATING MANUAL- MODEL : BS-101

Francesco Nidito. Programmazione Avanzata AA 2007/08

Schedule/BACnet Schedule

Digital Design Using VHDL Using Xilinx s Tool for Synthesis and ModelSim for Verification Part II

Calendar PPF Production Cycles Non-Production Activities and Events

Beginning Programming (Pascal) Lecture 75. Figure 1. type-declarations. simple-type. pointer-type. array-type. file-type. set-type.

Nights & Weekend ROB & PHIL DECEMBER 12, 2008

JavaScript I Language Basics

Organization of Programming Languages CS3200 / 5200N. Lecture 06

Chapter-8 DATA TYPES. Introduction. Variable:

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

Transcription:

PASCAL 11 OVERVIEW OF PASCAL LANGUAGE PASCAL, like BASIC, is a computer language However, PASCAL, unlike BASIC, is a Blocked Structured Language (BASIC is known as unstructured) Let look at a simple {BLOCK I) ----------------------------------------------------------------------------- {BLOCK II} num_two = 2; num_three = 3; sum : integer; ----------------------------------------------------------------------------- {BLOCK III} sum : = num_two + num_three; writeln (num_two, +, num_three is, sum ); end EXAMPLE is a simple PASCAL program When the program is executed, the following result will be displayed on the terminal 2 + 3 is 5 12 GENERAL FORMAT OF PASCAL PROGRAM (1) Program Heading (2) Declaration Section (3) Execution Section 13 GENERAL FORMAT OF PROGRAM HEADING (1) Program Identifier Identify the PASCAL program (2) List of External Files Specify a list of files which will be used by the program to communicate with the outside world 14 GENERAL FORMAT OF DECLARATION SECTION Declaration Section is consisted of (1) Label declaration (2) Constant declaration (3) Type declaration (4) Variable declaration (5) Procedure declaration (6) Function declaration 15 GENERAL FORMAT OF EXECUTION SECTION statement_1; statement_2; end CCASS / Computer Studies / Pascal Programming / Overview P1

There are different s of program statements : (1) Basic Statements (2) Control Statements i) Conditional Statements ii) Iterative Statements (3) Sequential File Handling Statements (4) Call subprogram statements (5) Comment Statements 2 OVERVIEW OF DECLARATION SECTION 21 CONSTANT DECLARATION identifier_1 = scalar_ant_1; identifier_2 = scalar_ant_2; pi = 31416; end Valid ant declaration g = 098; {real number} kelvin = -273; {integer} myname = ary ; {string} star = * ; {character} Iloveyou = true; {boolean} twopi = 20 * 31416; {arithmatic expression is accepted} Invalid ant declaration myrange = 1 9; {range is not allowed} Note A ant value cannot be changed by any part of the program min_value = 10; min_value : = 2; {illegal} end CCASS / Computer Studies / Pascal Programming / Overview P2

22 Data Type Array Structure Record File Subrange Data Type User-defined Enumerated User-defined Scalar Integer Standard Real Boolean Character Standard Data Type 221 Integer Valid PASCAL integer ants 28000, -28000, 1, 0, 20 maxint (predefined PASCAL ant represent highest integer number) Invalid PASCAL integer ants 1,400 (comas inserted) 123 (decimal inserted) 222 Real Number a) Decimal notation Valid PASCAL Real ants (in decimal notation) 31415927, -250, +0188, 01, 11 etc Invalid PASCAL Real ants (in decimal notation) 1 (no leading zero) 3 (no decimal point and fractional part) 1,0000 (comas is inserted) b) Scientific notation 223 Boolean a) true b) false Valid PASCAL Real ants (in Scientific notation) 5e6 (this represent 500000 or 5 10 6 ) -1e3 (this represent -1000 or -1 10 3 ) 1e-9 (this represent 0000000001 or 1 10 9 ) Invalid PASCAL Real ants (in Scientific notation) -23e2 (decimal after e) 224 Character - (char in short form) enclosed by a pair of SINGLE quotation marks Valid PASCAL Characters 'a' 'b' 'c' '*' '%' ' '' ' Invalid PASCAL Characters a (no quotation marks) "a" (use of double quotation mark is invalid) CCASS / Computer Studies / Pascal Programming / Overview P3

23 Variable Declaration - Define an object that can assume different value during the execution of program identifier_1 : data 1; identifier_2 : data 2; name_of_employee_1 : string; name_of_employee_2 : string; salary_of_employee_1 : real; paid_or_not : boolean; account_of_employee_1 : integer; sex_of_employee_1 : char; For the scalar standard data, the declaration of the iable can be directly made However, for all other data, the iable declaration must be made together with the declaration (will be discussed later) examscore = 0100; exam_result = examscore; end 24 Type Declaration 241 Scalar Standard Type - declaration is usually not needed 242 Scalar User-Defined Type (I) real Scalar Subrange Data Type - is a data composed of a specific range of any other standard or user-defined scalar s, except _name_identifier_1 = lower_limit_1upper_limit_1; _name_identifier_2 = lower_limit_2upper_limit_2; examscore = 0100; letter = 'a' 'z' ; exam_result : examscore; #iable declaration will be discussed later exam_result : = 60; end (II) Scalar Enumerated User-Defined Data Type CCASS / Computer Studies / Pascal Programming / Overview P4

- a series of data s defined by user _name_identifier_1 = (identifier_1, identifier_2, ) ; _name_identifier_2 = (identifier_3, identifier_4, ) ; day_of_week_ = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) day : day_of_week_; if ( ( day = Saturday ) or ( day = Sunday ) ) then writeln ( t is weekend ); for day := Monday to Friday do writeln ( oday is a school day ); end Common errors of Scalar Enumerated User-Defined Data Type a_ = ( brother, sister, son, mother ); b_ = ( brother, daughter, father ); 243 Structure Data Type (I) Array (II) Record (III) File (I) Array - a collection of data objects of identical by a single name _name_identifier_1 = array [t1 t2, t3 t4, ] of base1; _name_identifier_2 = array [t1 t2, t3 t4, ] of base2; 1 a = array [13] of real ; my_number : a; end 2 CCASS / Computer Studies / Pascal Programming / Overview P5

program example_2 (input,output); employee_name_ = array [1100] of string; employee_salary_ = array [1100] of integer; employee_name : employee_name_; employee_salary : employee_salary_; end 3 sample_ = array [-5020] of integer; sample : sample_; 4 day_of_the_week = (sun, mon, tue, wed, thur, fri, sat); weekday_ = array [day_of_the_week] of integer; weekday : weekday_; 5 lower_limit = -1 * maxint; upper_limit = maxint; x = array [lower_limit upper_limit] of integer; hello : x; Note i) The lower limit must be smaller than that of the upper limit ii) Both lower limit and upper limit can be negative iii) The base can be array (ie array of array) # Declaration of Record and File structure data will be discussed in later chapters CCASS / Computer Studies / Pascal Programming / Overview P6