Algorithm programming Ch 2 Introduction to Pascal Programming

  • Slides: 12
Download presentation
Algorithm & programming Ch. 2 Introduction to Pascal Programming 10/29/2020 Introdaction to Pascal programming

Algorithm & programming Ch. 2 Introduction to Pascal Programming 10/29/2020 Introdaction to Pascal programming

Sample programs n n n Print a welcoming message Introducing yourself to the computer

Sample programs n n n Print a welcoming message Introducing yourself to the computer Adding two numbers 10/29/2020 Introdaction to Pascal programming

A. Reserved Words(p. 28) n These words have been assigned special meanings and cannot

A. Reserved Words(p. 28) n These words have been assigned special meanings and cannot be changed E. g. And, Div, For, Begin, end, var, case, if, then , else, while, const, integer, string, boolean…etc 10/29/2020 Introdaction to Pascal programming

B. Identifiers Standard e. g. write, writeln, read, real…etc n User-defined e. g. Num

B. Identifiers Standard e. g. write, writeln, read, real…etc n User-defined e. g. Num 2, Sum, Add. Two. Numbers…etc n Ø No space, symbol Ø Begin with letter E. g. End. Of. Paper p. 44(1) 10/29/2020 Introdaction to Pascal programming

C. Punctuation Marks & Symbols n : =, : , <, >, +, -(negative

C. Punctuation Marks & Symbols n : =, : , <, >, +, -(negative sign or minus), *, /, ? , ( ), “ ”, . 10/29/2020 Introdaction to Pascal programming

D. Numbers, characters & strings n n n Integers and real numbers(real) Characters(char) Strings

D. Numbers, characters & strings n n n Integers and real numbers(real) Characters(char) Strings 10/29/2020 Introdaction to Pascal programming

Data Type n Integer Ø -32768 32767 n Real Ø Ø Ø n Ø

Data Type n Integer Ø -32768 32767 n Real Ø Ø Ø n Ø Ø Floating point notation=mantissa+exponent 123. 45=1. 2345 E+02 15. 2, 123. 0, 0. 00000012 Char ‘ ‘, ‘E’, ‘%’ String ‘Our’, ‘Our Lady’s’, ‘ 35. 7’, null Maximum: 255 char 10/29/2020 Introdaction to Pascal programming

E. Comment/Remarks n n They do not perform any action They gives information to

E. Comment/Remarks n n They do not perform any action They gives information to the programmer They cannot be inserted in the middle of words E. g. (*Test marks calculation*) (*Input of marks*) {The following program help us to , , , } p. 30 10/29/2020 Introdaction to Pascal programming

Program n Program heading Ø E. g. prog Check. Pass (input, output) n Declaration

Program n Program heading Ø E. g. prog Check. Pass (input, output) n Declaration part Ø Constant Declaration Variable Declaration Procedure Declaration n Program body Ø begin…End. Ø Ø p. 33 10/29/2020 Introdaction to Pascal programming

Program headings n Ø Ø Ø Specifies a name for the program Program Welcome,

Program headings n Ø Ø Ø Specifies a name for the program Program Welcome, Program Add. Two. Numbers; Program Introduce(input, output); 10/29/2020 Introdaction to Pascal programming

Declaration n Constant definition Ø Const Rate=0. 08; Pi=3. 14159; Max. No=100; n Variable

Declaration n Constant definition Ø Const Rate=0. 08; Pi=3. 14159; Max. No=100; n Variable definition Ø Ø Ø Num 1, Num 2, Sum : integer; Name: string; Amount, Interest: real; Found: boolean; 10/29/2020 Introdaction to Pascal programming

Programming Exercises n n n Print your email address Print your class time table

Programming Exercises n n n Print your email address Print your class time table Print with the following sample output using the constant ‘Computer’: Computer. Comuter 10/29/2020 Introdaction to Pascal programming