120 likes | 133 Views
Learn the basics of Pascal programming, including reserved words, identifiers, data types, and program structure. Explore sample programs like printing a welcoming message and adding two numbers.
E N D
Algorithm & programming Ch.2 Introduction to Pascal Programming Introdaction to Pascal programming
Sample programs • Print a welcoming message • Introducing yourself to the computer • Adding two numbers Introdaction to Pascal programming
A. Reserved Words(p.28) • 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 Introdaction to Pascal programming
B. Identifiers • Standard e.g. write, writeln, read, real…etc • User-defined e.g.Num2, Sum, AddTwoNumbers…etc • No space, symbol • Begin with letter E.g. EndOfPaper p.44(1) Introdaction to Pascal programming
C. Punctuation Marks & Symbols • :=, :, <, >, +, -(negative sign or minus), *, /, ?, ( ), “”, . Introdaction to Pascal programming
D. Numbers, characters & strings • Integers and real numbers(real) • Characters(char) • Strings Introdaction to Pascal programming
Data Type • Integer • -3276832767 • Real • Floating point notation=mantissa+exponent • 123.45=1.2345E+02 • 15.2,123.0, 0.00000012 • Char • ‘‘, ‘E’, ‘%’ • String • ‘Our’, ‘Our Lady’s’, ‘35.7’, null • Maximum: 255 char Introdaction to Pascal programming
E. Comment/Remarks • 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 Introdaction to Pascal programming
Program • Program heading • E.g. prog CheckPass (input, output) • Declaration part • Constant Declaration • Variable Declaration • Procedure Declaration • Program body • begin…End. p.33 Introdaction to Pascal programming
Program headings • Specifies a name for the program • Program Welcome, • Program AddTwoNumbers; • Program Introduce(input, output); Introdaction to Pascal programming
Declaration • Constant definition • Const Rate=0.08; • Pi=3.14159; • MaxNo=100; • Variable definition • Num1, Num2, Sum :integer; • Name:string; • Amount, Interest: real; • Found: boolean; Introdaction to Pascal programming
Programming Exercises • Print your email address • Print your class time table • Print with the following sample output using the constant ‘Computer’: Introdaction to Pascal programming