note_03 - CPSC 110 PASCAL PROGRAMMING Developed at...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CPSC – 110 PASCAL PROGRAMMING • Developed at Dartmouth (1970) by Wirth • Designed as a language that can be utilized to develop programs in a structured manner. •A high-level general purpose language
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 General Format of a Pascal Program Program Heading; Var Variable Declaration Section; Begin Body of program Input-processing-output End.
Background image of page 2
3 program Sample; var N1,N2,SUM;integer; begin writeln(‘Enter two numbers’); readln(N1,N2); SUM := N1+N2; writeln(N1,’plus’,N2,’equals’,SUM); writeln(‘Enter another two numbers’); readln(N1,N2); SUM := N1+N2; writeln(N1,’plus’,N2,’equals’,SUM) end. Sample Dialogue: Enter two numbers 4 5 4 plus 5 equals 9 Enter another two numbers 8 9 8 plus 9 equals 17
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Variable Declarations Variables – named memory locations. Capable of holding 1 value. Value has a specific type. Value can be changed. Programmer chooses the name and type. Rules for variable names: IDENTIFIERS 1. Start with letter or underscore. 2. Length (Complier recognize up to 63 characters). 3. Letters, digits or underscore
Background image of page 4
5 Variable Type Each variable has a specified type. Type determines: What sort of data may be stored in that variable. What operations are permissible with that variable. Primitive (Pre-defined) Types: –I n t e g e r Real Character (Char) Boolean
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 var Section – where variables are declared. eg. var x,y,z: integer; time: Real; Primitive Types 1. Integer * Whole numbers * No decimal point * Exact value When you declare a variable to be of type Integer, how much memory is allocated?
Background image of page 6
7 Built-in Function Maxint – built-in, pre-defined function. Will return the largest value that can be stored in an int variable.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Other Integer Primitive Types Byte : 0. ..255 Shortint : -128. ...127 Word : 0...65535 Longint : -2,147,483,648…2,147,483,647
Background image of page 8
9 2. Real a. Decimal format. * Must have decimal pt. * Must have digit BEFORE and AFTER. 1.7 Valid .7 Invalid Need 0.7 b. Scientific or E-notation format . 2.45 E 14 2.45 x 10 14 1.60 E –5 1.60 x 10 -5 Move decimal pt to right (Positive exponent) Move decimal pt to left (Negative exponent)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Other Real types : Bytes Sig Digits Single : 1.5x10 45 ….3.4x10 38 47 - 8 Double : 5.0x10 -324 ...1.7x10 308 8 15-16 Extended : 3.4x10 -4932 ..1.1x10 4932 10 19-20 Real : 2.9x10 -38 6 11-12
Background image of page 10
11 Type Compatibilities : var x : Real; x:= 10; Integer assigned to real variable. Allowed – integer will be stored as real 10.0 Var y: integer; Y:= 2.7; Real assigned to integer variable Illegal – Will not execute Integer to Integer Real to Real OK
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 How to Determine the Type of an Arithmetic Expression 1. Combining something of type real with something either of type integer or type real always yields something of type real.
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 51

note_03 - CPSC 110 PASCAL PROGRAMMING Developed at...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online