pascal programming session 1

20
Pascal Programming http://ashesh.ramjeeawon.info Management Student/ Freelance Developer University of Mauritius Module Pre-Requisites: Problem-Solving Techniques Session 1: Pascal Fundamentals

Upload: ashesh-r

Post on 21-May-2015

3.646 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Pascal Programming Session 1

Pascal Programming

http://ashesh.ramjeeawon.infoManagement Student/ Freelance DeveloperUniversity of Mauritius

Module Pre-Requisites:

Problem-Solving Techniques

Session 1: Pascal Fundamentals

Page 2: Pascal Programming Session 1

Pascal Programming

Today’s Session

1. Intro to Pascal

2. History of Pascal

3. Getting the tools (IDE/Compiler)

4. The basic structure of a Pascal Program

5. Identifiers

6. Data Types

7. Input and Output

Page 3: Pascal Programming Session 1

Pascal Programming

Intro to Pascal

Pascal is a general-purpose, high-level programming language

Derived from Algol-60

Specifically designed to encourage the use of Structured Programming

Page 4: Pascal Programming Session 1

Pascal Programming

Intro to Pascal

Pascal was named in honour of Blaise Pascal (1623 – 1662)

Brilliant French Scientist and Mathematician Invented the word’s first calculating machine (Pascaline)

Page 5: Pascal Programming Session 1

Pascal Programming

History of Pascal

Developed in the early 1970s by Niklaus Wirth at

The Technical University in Zurich, Switzerland

Page 6: Pascal Programming Session 1

Pascal Programming

History of Pascal

In 1983, Borland International began marketing of an inexpensive compiler called Turbo Pascal.

Page 7: Pascal Programming Session 1

Pascal Programming

Getting the tools

Page 8: Pascal Programming Session 1

Pascal Programming

Getting the tools

Turbo Pascal for WindowsGetting hands dirty with the IDEInstalling the Turbo PascalCode writing aidsCompiling DebuggingSaving source code - .pas formatCVS

Page 9: Pascal Programming Session 1

Pascal Programming

The basic structure of a Pascal Program

PROGRAM ProgramName (FileList);

CONST  (* Constant declarations *)

TYPE  (* Type declarations *)

VAR  (* Variable declarations *)

(* Subprogram definitions *)

BEGIN  (* Executable statements *)END.

Page 10: Pascal Programming Session 1

Pascal Programming

Exercise Time

1. Open your IDE2. Create a complete “dummy” program3. Then save it on your desktop as4. Alpha.pas5. Note: No compilation is required6. Aim 1: to get hands dirty with the IDE 7. Aim 2: understand the structure of a

Pascal Program

Page 11: Pascal Programming Session 1

Pascal Programming

Identifiers

Must begin with a letter from the English alphabet.

Can be followed by alphanumeric characters (alphabetic characters and numerals) and possibly the underscore (_).

May not contain certain special characters, many of which have special meanings in Pascal.~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / |

Page 12: Pascal Programming Session 1

Pascal Programming

Identifiers

Page 13: Pascal Programming Session 1

Pascal Programming

Pascal is not case sensitive!

Turbo Pascal allows you to write names with upper and lowercase letters.

PART_NUMBER part_number PaRt_NumBer Part_Number

Pascal would consider the above identifiers as the same.

Page 14: Pascal Programming Session 1

Pascal Programming

Memory storage

Page 15: Pascal Programming Session 1

Pascal Programming

Pascal Data Types

The basic data types in Pascal include:integerrealcharBoolean

Page 16: Pascal Programming Session 1

Pascal Programming

Pascal Data Types

More: http://www.geocities.com/hotdogcom/ptutor/chap03.html

Page 17: Pascal Programming Session 1

Pascal Programming

Variable declaration

var  IdentifierList1 : DataType1;  IdentifierList2 : DataType2;  IdentifierList3 : DataType3;  ...

var  age, year, grade : integer;  circumference : real;  LetterGrade : char;  DidYouFail : Boolean;

Page 18: Pascal Programming Session 1

Pascal Programming

Input and Output

Input from keyboardReadln(var);

Output to screenWriteln(‘Hello World!’);

Page 19: Pascal Programming Session 1

Pascal Programming

The End – Thank you for your kind attention

References:http://taoyue.com/tutorials/pascal/contents.htmlB. Gottfried, Programming with Pascal, 2nd

Edition, McGrawHill

Page 20: Pascal Programming Session 1

Pascal Programming

http://ashesh.ramjeeawon.infoBlog: http://asheshr.wordpress.comManagement Student/ Freelance DeveloperUniversity of MauritiusBCS Student Member