204111  Computers and Programming อนันต์ ผลเพิ่ม Anan Phonphoem http://www.cpe.ku.ac.th/~anan [email_address]
Outline Intro to computer Computer components How can we load and run program? Programming languages Problem solving and programming Programming strategy Intro to Pascal Program structure Basic elements (reserved words, identifiers)
Categories of Computers Microcomputer Personal Computer, Desktop computer Notebook, Laptop, Palmtop Use by one person at a time Minicomputer Faster speed Many users at the same time Mainframe -> Supercomputer High computation power
Categories of Computers Workstation CAD Workstation Unix Workstation Server Client /Server (Networks)
Computer Components
Computer Components HD CPU Main Memory Secondary Memory Input Devices Output Devices
Computer Memory 1. Main Memory 2. Secondary Memory
1. Main Memory Store information 100 -34.9 A 23 W 000 001 002 003 ... 999 Memory Cell Memory  Address
1. Main Memory Memory Cell    Byte    Bit 1 Byte = 8 bits Can be divided into 2 Categories RAM (Random Access Memory) ROM (Read Only Memory)
2. Secondary Memory (Storage) Floppy disk Hard disk CD-ROM Tape Information called “file” (data file, output file, program file) 1 Kbyte = 2 10  = 1024 bytes 1 Mbyte = 2 20  = 1,048,576 bytes 1 Gbyte = 2 30  = 1,073,741,824 bytes
Main VS. Secondary Memory Main Memory Much faster More expensive Volatile (RAM) Secondary Memory Slower Less expensive Permanent
Computer Components HD CPU Main Memory Secondary Memory Input Devices Output Devices
Central Processor Unit (CPU) Retrieve information from memory Calculate Put back results to memory Intel / AMD (Pentium / Athlon)
How can we load and run program? Boot process Load OS into Memory Tell user to load and run Program “p1” User start using program HW OS Secondary Storage p1 USER
Programming Language Machine Language Assembly Language High-Level Language CPU can execute only the machine language
How can a non-machine language program be executed? 2 methods Interpretation Translation
The interpretation Process Source Program Input Data Interpreter (on computer) Output
Translation Process Translation Phase Link Phase Execute Phase Source Program Translator Object Program Library Linker Execute Program Output CPU Input Data
Translators Assembler (assembly) Compiler (High-level language)
High-Level Languages Procedural Language Fortran Cobol Basic C Pascal Object-Oriented Language C++ Functional Language Lisp Logic Language Prolog
Problem Solving and Programming Solve Problems Combine art and science Art Transform a description (word to equation) Difficult (problem is not clear, input, output) Science Knowledge of problems Equation and formula
Programming Strategy Don’t rush to key in the computer Think carefully about the problem Try to solve by hand Plan your program Test by hand if possible Start programming Program Compilation Testing / Debug Documentation Maintenance
Introduction to Pascal Procedural programming language Developed by Prof.Niklaus Wirth (Switzerland, 1970s) Named in honor to mathematician, Blaise Pascal Most popular -> Turbo Pascal
Pascal Program Structure Program Heading Declarations Main Routine (Program body)
Pascal Program Structure program myFirstProgram; const myStudentId = 1234567; 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
Basic Elements of Pascal Character set Reserved words Identifiers Constants / Variables Statement / Expression Function / Procedure
Character Set Three categories Letter (A…Z, a…z) Digit (0…9) Special character (+ - * / _ = ! <> []{})
Reserved Words  ( คำสงวน ) Predefined meaning and usage Cannot be redefined by the programmer Examples program begin / end const / var etc.
Reserved Words  ( คำสงวน ) program myFirstProgram; const myStudentId = 1234567; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end.
Identifiers   ( คำบ่งช ี้ ) Symbolic names for program elements Program name Variable name Data Type name Etc. Rules for constructing identifiers Letters, digits, and under score (_) First character   letter Can be long (63 char) Reserved words are not allowed
Identifiers ( คำบ่งช ี้ ) program myFirstProgram; const myStudentId = 1234567; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end.
Identifier examples Valid examples score, count, total score1, count99, total09 score_1, count_99, total_99 myStudentId my_student_id  Invalid examples point&score total-number  9points
Notes for Identifiers Identifiers are case-insensitive mystudentId Mystudentid MYSTUDENTID Some identifiers are predefined meanings (Standard Identifiers )   interger, real write, writeln, read, readln
Standard Identifiers program myFirstProgram; const myStudentId = 1234567; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end.

01 intro-computer-pascal

  • 1.
    204111 Computersand Programming อนันต์ ผลเพิ่ม Anan Phonphoem http://www.cpe.ku.ac.th/~anan [email_address]
  • 2.
    Outline Intro tocomputer Computer components How can we load and run program? Programming languages Problem solving and programming Programming strategy Intro to Pascal Program structure Basic elements (reserved words, identifiers)
  • 3.
    Categories of ComputersMicrocomputer Personal Computer, Desktop computer Notebook, Laptop, Palmtop Use by one person at a time Minicomputer Faster speed Many users at the same time Mainframe -> Supercomputer High computation power
  • 4.
    Categories of ComputersWorkstation CAD Workstation Unix Workstation Server Client /Server (Networks)
  • 5.
  • 6.
    Computer Components HDCPU Main Memory Secondary Memory Input Devices Output Devices
  • 7.
    Computer Memory 1.Main Memory 2. Secondary Memory
  • 8.
    1. Main MemoryStore information 100 -34.9 A 23 W 000 001 002 003 ... 999 Memory Cell Memory Address
  • 9.
    1. Main MemoryMemory Cell  Byte  Bit 1 Byte = 8 bits Can be divided into 2 Categories RAM (Random Access Memory) ROM (Read Only Memory)
  • 10.
    2. Secondary Memory(Storage) Floppy disk Hard disk CD-ROM Tape Information called “file” (data file, output file, program file) 1 Kbyte = 2 10 = 1024 bytes 1 Mbyte = 2 20 = 1,048,576 bytes 1 Gbyte = 2 30 = 1,073,741,824 bytes
  • 11.
    Main VS. SecondaryMemory Main Memory Much faster More expensive Volatile (RAM) Secondary Memory Slower Less expensive Permanent
  • 12.
    Computer Components HDCPU Main Memory Secondary Memory Input Devices Output Devices
  • 13.
    Central Processor Unit(CPU) Retrieve information from memory Calculate Put back results to memory Intel / AMD (Pentium / Athlon)
  • 14.
    How can weload and run program? Boot process Load OS into Memory Tell user to load and run Program “p1” User start using program HW OS Secondary Storage p1 USER
  • 15.
    Programming Language MachineLanguage Assembly Language High-Level Language CPU can execute only the machine language
  • 16.
    How can anon-machine language program be executed? 2 methods Interpretation Translation
  • 17.
    The interpretation ProcessSource Program Input Data Interpreter (on computer) Output
  • 18.
    Translation Process TranslationPhase Link Phase Execute Phase Source Program Translator Object Program Library Linker Execute Program Output CPU Input Data
  • 19.
    Translators Assembler (assembly)Compiler (High-level language)
  • 20.
    High-Level Languages ProceduralLanguage Fortran Cobol Basic C Pascal Object-Oriented Language C++ Functional Language Lisp Logic Language Prolog
  • 21.
    Problem Solving andProgramming Solve Problems Combine art and science Art Transform a description (word to equation) Difficult (problem is not clear, input, output) Science Knowledge of problems Equation and formula
  • 22.
    Programming Strategy Don’trush to key in the computer Think carefully about the problem Try to solve by hand Plan your program Test by hand if possible Start programming Program Compilation Testing / Debug Documentation Maintenance
  • 23.
    Introduction to PascalProcedural programming language Developed by Prof.Niklaus Wirth (Switzerland, 1970s) Named in honor to mathematician, Blaise Pascal Most popular -> Turbo Pascal
  • 24.
    Pascal Program StructureProgram Heading Declarations Main Routine (Program body)
  • 25.
    Pascal Program Structureprogram myFirstProgram; const myStudentId = 1234567; 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
  • 26.
    Basic Elements ofPascal Character set Reserved words Identifiers Constants / Variables Statement / Expression Function / Procedure
  • 27.
    Character Set Threecategories Letter (A…Z, a…z) Digit (0…9) Special character (+ - * / _ = ! <> []{})
  • 28.
    Reserved Words ( คำสงวน ) Predefined meaning and usage Cannot be redefined by the programmer Examples program begin / end const / var etc.
  • 29.
    Reserved Words ( คำสงวน ) program myFirstProgram; const myStudentId = 1234567; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end.
  • 30.
    Identifiers ( คำบ่งช ี้ ) Symbolic names for program elements Program name Variable name Data Type name Etc. Rules for constructing identifiers Letters, digits, and under score (_) First character  letter Can be long (63 char) Reserved words are not allowed
  • 31.
    Identifiers ( คำบ่งชี้ ) program myFirstProgram; const myStudentId = 1234567; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end.
  • 32.
    Identifier examples Validexamples score, count, total score1, count99, total09 score_1, count_99, total_99 myStudentId my_student_id Invalid examples point&score total-number 9points
  • 33.
    Notes for IdentifiersIdentifiers are case-insensitive mystudentId Mystudentid MYSTUDENTID Some identifiers are predefined meanings (Standard Identifiers ) interger, real write, writeln, read, readln
  • 34.
    Standard Identifiers programmyFirstProgram; const myStudentId = 1234567; var courseTaken: integer; begin write(‘Please Enter a number of courses’); read(‘courseTaken’); writeln(‘Student’, myStudentId, ‘ takes ’, courseTaken, ‘ courses in this semester’); end.