01 intro-computer-pascal
-
Upload
serghei-urban -
Category
Education
-
view
708 -
download
0
Transcript of 01 intro-computer-pascal
![Page 1: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/1.jpg)
1
204111 Computers and Programming
อนั�นัต์� ผลเพิ่��มAnan Phonphoem
http://www.cpe.ku.ac.th/~anan
![Page 2: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/2.jpg)
2
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)
![Page 3: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/3.jpg)
3
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
![Page 4: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/4.jpg)
4
Categories of Computers Workstation
CAD Workstation Unix Workstation
Server Client /Server (Networks)
![Page 5: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/5.jpg)
5
Computer Components
![Page 6: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/6.jpg)
6
CPU
MainMemory
HD
Computer ComponentsSecondary Memory
Input Devices
Output Devices
![Page 7: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/7.jpg)
7
Computer Memory
1. Main Memory2. Secondary Memory
![Page 8: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/8.jpg)
8
1. Main Memory Store information
100-34.9
A23
W
000001002003...
999
Memory Cell
Memory Address
![Page 9: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/9.jpg)
9
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)
![Page 10: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/10.jpg)
10
2. Secondary Memory (Storage) Floppy disk Hard disk CD-ROM Tape Information called “file” (data file,
output file, program file) 1 Kbyte = 210 = 1024 bytes 1 Mbyte = 220 = 1,048,576 bytes 1 Gbyte = 230 = 1,073,741,824 bytes
![Page 11: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/11.jpg)
11
Main VS. Secondary Memory Main Memory
Much faster More expensive Volatile (RAM)
Secondary Memory Slower Less expensive Permanent
![Page 12: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/12.jpg)
12
CPU
MainMemory
HD
Computer ComponentsSecondary Memory
Input Devices
Output Devices
![Page 13: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/13.jpg)
13
Central Processor Unit (CPU) Retrieve information from memory Calculate Put back results to memory Intel / AMD (Pentium / Athlon)
![Page 14: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/14.jpg)
14
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
HWOS
SecondaryStorage
p1 USER
![Page 15: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/15.jpg)
15
Programming Language Machine Language Assembly Language High-Level Language CPU can execute only the machine
language
![Page 16: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/16.jpg)
16
How can a non-machine language program be executed?
2 methods Interpretation Translation
![Page 17: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/17.jpg)
17
The interpretation Process
Source Program
Input Data
Interpreter(on computer)
Output
![Page 18: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/18.jpg)
18
Translation Process Translation Phase Link Phase Execute Phase
SourceProgram Translator Object
Program
Library
Linker ExecuteProgram
Output CPU Input Data
![Page 19: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/19.jpg)
19
Translators Assembler (assembly) Compiler (High-level language)
![Page 20: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/20.jpg)
20
High-Level Languages Procedural Language
Fortran Cobol Basic C Pascal
Object-Oriented Language C++
Functional Language Lisp
Logic Language Prolog
![Page 21: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/21.jpg)
21
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
![Page 22: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/22.jpg)
22
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
![Page 23: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/23.jpg)
23
Introduction to Pascal Procedural programming language Developed by Prof.Niklaus Wirth
(Switzerland, 1970s) Named in honor to mathematician,
Blaise Pascal Most popular -> Turbo Pascal
![Page 24: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/24.jpg)
24
Pascal Program Structure Program Heading Declarations Main Routine (Program body)
![Page 25: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/25.jpg)
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
![Page 26: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/26.jpg)
26
Basic Elements of Pascal Character set Reserved words Identifiers Constants / Variables Statement / Expression Function / Procedure
![Page 27: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/27.jpg)
27
Character Set Three categories
Letter (A…Z, a…z) Digit (0…9) Special character (+ - * / _ = ! <> []
{})
![Page 28: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/28.jpg)
28
Reserved Words (คำ��สงวน) Predefined meaning and usage Cannot be redefined by the
programmer Examples
program begin / end const / var etc.
![Page 29: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/29.jpg)
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.
![Page 30: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/30.jpg)
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
![Page 31: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/31.jpg)
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.
![Page 32: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/32.jpg)
32
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
![Page 33: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/33.jpg)
33
Notes for Identifiers Identifiers are case-insensitive
mystudentId Mystudentid MYSTUDENTID
Some identifiers are predefined meanings (Standard Identifiers) interger, real write, writeln, read, readln
![Page 34: 01 intro-computer-pascal](https://reader036.fdocument.pub/reader036/viewer/2022062418/555e024dd8b42a3f618b5588/html5/thumbnails/34.jpg)
34
Standard Identifiersprogram 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.