Beruflich Dokumente
Kultur Dokumente
204111
Computers and Programming
Anan Phonphoem
anan@cpe.ku.ac.th
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
Workstation
Minicomputer
Categories of Computers
Microcomputer
Faster speed
Many users at the same time
CAD Workstation
Unix Workstation
Server
Computer Components
Computer Components
Secondary
Memory
Main
Memory
HD
CPU
5
Input Devices
Output Devices
6
Computer Memory
1. Main Memory
1. Main Memory
2. Secondary Memory
Store information
Memory
Address
000
001
002
003
...
100
-34.9
A
23
999
Memory Cell
1. Main Memory
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
Computer Components
Secondary
Memory
Main Memory
10
Much faster
More expensive
Volatile (RAM)
Main
Memory
Secondary Memory
HD
Slower
Less expensive
Permanent
CPU
11
Input Devices
Output Devices
12
Boot process
Secondary
Storage
HW
OS p1
13
14
Programming Language
Machine Language
Assembly Language
High-Level Language
CPU can execute only the machine
language
2 methods
Interpretation
Translation
15
16
Translation Process
Source Program
Interpreter
(on computer)
USER
Output
Input Data
Translation Phase
Link Phase
Execute Phase
Source
Program
Translator
Output
17
Library
Object
Program
CPU
Linker
Execute
Program
Input Data
18
Translators
High-Level Languages
Assembler (assembly)
Compiler (High-level language)
Procedural Language
Fortran
Cobol
Basic
C
Pascal
Object-Oriented Language
Functional Language
Lisp
Logic Language
Prolog
C++
19
Programming Strategy
Solve Problems
Combine art and science
Art
Science
20
Knowledge of problems
Equation and formula
21
Introduction to Pascal
22
23
Program Heading
Declarations
Main Routine (Program body)
24
Program Heading
program myFirstProgram;
const
Declarations
myStudentId = 1234567;
var
courseTaken: integer;
begin
Program Body
write(Please Enter a number of courses);
read(courseTaken);
writeln(Student, myStudentId, takes , courseTaken,
courses in this semester);
end.
Character set
Reserved words
Identifiers
Constants / Variables
Statement / Expression
Function / Procedure
25
Reserved Words ()
Character Set
Three categories
26
program
begin / end
const / var
etc.
27
Reserved Words ()
28
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.
29
Program name
Variable name
Data Type name
Etc.
Letters, digits, and under score (_)
First character letter
Can be long (63 char)
Reserved words are not allowed
30
Identifiers ()
Identifier examples
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.
Valid examples
Invalid examples
point&score
total-number
9points
31
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.
mystudentId
Mystudentid
MYSTUDENTID
32
interger, real
write, writeln, read, readln
33
34