1 st semester 2004 1 Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

1 Demo Reading Assignments Important terms & concepts Fundamental Data Types Identifier Naming Arithmetic Operations Sample Programs CSE Lecture.
1 Flowchart If – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem
Program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
JavaScript, Third Edition
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Thanachat Thanomkulabut
Computers and Programming อนันต์ ผลเพิ่ม Anan Phonphoem
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Introduction to Pascal The Basics of Program writing.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
C# Basic Concept Thanachat Thanomkulabut. Naming Rules  Letters, digits and underscores(_)  First character  letter or _  Up to 63 characters long.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Programming, an introduction to Pascal
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
2 nd Semester Module1 Introduction to Computer and Programming อภิรักษ์ จันทร์สร้าง Aphirak Jansang
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Chapter 2 – part b Brent M. Dingle Texas A&M University
Chapter # 2 Part 2 Programs And data
BASIC ELEMENTS OF A COMPUTER PROGRAM
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Data Types, Identifiers, and Expressions
The Selection Structure
Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
C++ for Engineers and Scientists Second Edition
Basic Elements of C++ Chapter 2.
IDENTIFIERS CSC 111.
Data Types, Identifiers, and Expressions
Programming Funamental slides
Chapter # 2 Part 2 Programs And data
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Primitive Types and Expressions
Presentation transcript:

1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department Kasetsart University, Bangkok THAILAND

1 st semester Outlines Pascal Program Structure Constant/Variable STATEMENT EXPRESSION

1 st semester Identifiers – AGAIN FROM Lecture1 Symbolic names for program elements Rules for constructing identifiers Letters, digits, and under score (_) First character  letter Can be long (63 char) Reserved words are not allowed

1 st semester Pascal PROGRAM STRUCTURE program myFirstProgram; const myStudentId = ; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end. Program Heading Declarations Program Body

1 st semester Pascal PROGRAM STRUCTURE PROGRAM HEADING DECLARATIONS NONAME00.PAS PROGRAM BODY PROGRAM HEADING

1 st semester PROGRAM HEADING Place at the beginning of file Parameter input - keyboard output - monitor Heading Syntax program YOURPROGNAME (input, output); program YOURPROGNAME ;

1 st semester PROGRAM HEADING Example Valid PROGRAM Heading program calulate_grade (input, output); program square_root (input, output); program lab3; Invalid PROGRAM Heading program registration (input, output) program polynomial (input, ); program calculate-area (input, output);

1 st semester Pascal PROGRAM STRUCTURE NONAME00.PAS PROGRAM HEADING DECLARATIONS PROGRAM BODY PROGRAM HEADING DECLARATIONS

1 st semester Declarations 1. CONSTANT 2. VARIABLE

1 st semester CONSTANT Value cannot be changed Syntax Const identifier1 = constant expression 1 ; … indentifier_n = constant expression n ;

1 st semester Constant Declaration Example Const MyLargeInteger = 9999; {value is 9999} MySmallInteger = -MyLargeInteger; {value is -9999} Star = ‘*’; {value is symbol *} FirstMonth = ‘January’; {value is string ‘January’}

1 st semester VARIABLE Referred to an individual cell in main memory Value can be changed Syntax VAR identifier1 : data type; identifier3, identifier2 : data type ;

1 st semester VARIABLE Declaration Example Var X, Y : Real; AREA: Real; AREA Y XNONAME00.PAS MAIN MEMORY

1 st semester VARIABLE Data type CHAR INTEGER REAL BOOLEAN

1 st semester CHAR data type A single character Letter Digit Symbol Character value in program must be enclosed with single quote gA1* EX. ‘g’ ‘A’ ‘1’ ‘*’ A sequence of character is known as STRING Harry PotterProtocol System EX. ‘Harry Potter’, ‘Protocol System’

1 st semester Example CHAR data type Declaration Var ch1 : char; st1 : string; ch1 st1 MAX=255

1 st semester INTEGER data type Value can be positive or negative number In i386, integer variable can keep value from to Bigger than integer is longint data type to Can be used with arithmetic operation

1 st semester Example Integer data type Declaration Var num1 : integer; num2, num3 : integer ; num4 : longint; num6, num7 : longint;

1 st semester REAL data type Integer + Fraction Example Integer Fraction

1 st semester REAL Data type Can be used in following notation Decimal notation Example 2.50, Scientific notation number x 10 exponent Are expressed in Pascal using the syntax E Example 2.5E+00, E1

1 st semester Real data type Can be used with +, -, *, / and comparison Example.2345  Invalid 1,  Invalid  Valid 50E10  Valid

1 st semester BOOLEAN data type TRUEFALSE Value can be TRUE or FALSE Use Frequently in Control Statement Example Variable A is the boolean data type. We can use following 11>2 A := 11>2; True

1 st semester CONCLUSION FROM PREVIOUS

1 st semester Pascal PROGRAM STRUCTURE NONAME00.PAS PROGRAM HEADING DECLARATIONS PROGRAM BODY PROGRAM HEADING DECLARATIONS PROGRAM BODY

1 st semester PROGRAM BODY Begin statement1; statement2; … statementn;End. PROGRAM BODY

1 st semester EXPRESSION ARITHMETIC EXPRESSION BOOLEAN EXPRESSION

1 st semester Arithmetic Expression Operators: + - * / DIV (truncated divide) MOD (remainder after division) Example 11/2 = DIV 2 = 5 11 MOD 2 = 1

1 st semester Arithmetic Expression (width + length) (12*(top – bottom)) 34+54/78*12

1 st semester Precedence rules for arithmetic operators 1.( ) parentheses 2.Unary + and – 3.*, /, DIV, MOD 4.+ – 5.If equal precedence, left to right Examples -a+j/-w = (-a) + (j / (-w)) C*23/6+23mod2 = ((C*23)/6) + (23 mod 2)

1 st semester Precedence rules for arithmetic operators Examples X:=A+B/C; WRONG X:=A+(B/C); X:=(A+B)/C; TRUE

1 st semester Boolean Expression Two possible values: True, False 1.Relation Operator =,, <>, = 2.Boolean Operator AND, OR, NOT 15 = 34 False < 17 True True

1 st semester Truth table AND OR T TTT T FFT F TFT F FFF

1 st semester Boolean Expression (30 12) (30 < 35) OR (99 <= 99.80) F F T  = T T T  =

1 st semester STATEMENT ASSIGNMENT STATEMENT OUTPUT STATEMENT INPUT STATEMENT

1 st semester ASSIGNMENT STATEMENT For storing the value or a computational result into the variable. Assignment Statement variable := expression; Example AREA := X * Y;

1 st semester ASSIGNMENT STATEMENT EXAMPLE From SUM := SUM + ITEM; ITEMSUM Before ASSIGNMENT SUM After ASSIGNMENT

1 st semester ASSIGNMENT STATEMENT EXAMPLE From AREA := X * Y; * AREAXY10020? Before ASSIGNMENT AREAXY After ASSIGNMENT

1 st semester OUTPUT STATEMENT Use following two command for output to the screen write ( ); After write, remember the location Start at that location for the next time writeln ( ); When done, go to new line and left side Syntax Write(parameter1, parameter2, …, parametern); Writeln(parameter1, parameter2, …, parametern);

1 st semester EXAMPLE WRITE Write(‘price=‘); {statement 1} Write(’10bt’); {statement 2} Line1 Before statement 1 Line1 rpeci= After statement 1 Line1 rpecib01=t After statement 2

1 st semester EXAMPLE WRITELN Writeln(‘price=‘); {statement 1} Write(’10bt’); {statement 2} Line1 Before statement 1 After statement 1 Line1 rp eci= Line2 b01t After statement 2 Line1 rp eci= Line2

1 st semester Output statement example Write (‘price =‘, price); Write (‘total = ‘, price); Writeln (‘the total is’,’ ‘, total, ‘unit’); Writeln (‘hello’,’how are you’, ‘doing’);

1 st semester Formatted output Integer : width Real_data : width Real_data : width : decimal String_data : width

1 st semester Format: Integer Data type Total:=2500; Writeln(total:6);1Line Line Line1

1 st semester Format: Real Data type PI:= ; Writeln(PI:9);1Line Line Line1 E

1 st semester Format: Real Data type PI:= ; Writeln(PI:5:2);1Line Line Line1

1 st semester Format: String Data type st1:=‘ABC’; Writeln(st1:5);1Line Line1 CBA Line1

1 st semester WHY Output looks like below?

1 st semester WHY Output looks like below?

1 st semester INPUT STATEMENT Use following two command for get input from the device into variable read() readln() Syntax read (parameter1, parameter2, … ); readln (parameter1, parameter2, …);

1 st semester INPUT STATEMENT Example read( studentid, course, section); IF We have input 

1 st semester INPUT STATEMENT How to input if we use following statement? read(data1, data2); Data type 1 Data type 2 INPUT VALUE in Data1 VALUE in Data2 REMARK INTEGER 13□151315Blank is skip INTEGERCHAR13□M13□Blank is char INTEGERSTRING13□AX□13□AX□Blank is part of STRING For INTEGER, Blank is need for separate numbers. For CHAR/STRING, no blank is need for separate.

1 st semester INPUT STATEMENT What will happened? If Number of input > number of variable Exceed input will be lost If Number of input < number of variable Program will pause and wait for the require input

1 st semester CONCLUSION FROM PREVIOUS

1 st semester Conclusions

1 st semester CONCLUSION program myFirstProgram; const myStudentId = ; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end. Program Heading Declarations Program Body

1 st semester EXAMPLE PROGRAM 1

1 st semester EXAMPLE PROGRAM 2 Problem Write a program for find the area of the circle. r AREA := Pi * Radius * Radius; a = ¶r 2 CONSTANT VARIABLE VARIABLE

1 st semester EXAMPLE PROGRAM 2 OUTPUT

1 st semester EXAMPLE PROGRAM 3 OUTPUT

1 st semester Error 3: Unknown Identifier num6 is not defined in declaration part

1 st semester Error 85: “;” expected. Current Cursor ;

1 st semester Error 94: “.” expected Have to use.(dot) for the end of program body

1 st semester What will we learn in Next Class? Flowchart If the Else