Computers and Programming: Anan Phonphoem Anan@cpe - Ku.ac - TH
Computers and Programming: Anan Phonphoem Anan@cpe - Ku.ac - TH
Outline
Intro to computer Computer components How can we load and run program? Programming languages Problem solving and programming Programming strategy Intro to Pascal
Categories of Computers
Microcomputer
Personal Computer, Desktop computer Notebook, Laptop, Palmtop Use by one person at a time Faster speed Many users at the same time High computation power
3
Minicomputer
Categories of Computers
Workstation
Server
Computer Components
Computer Components
Secondary Memory
Main Memory
Output Devices
6
Computer Memory
1. Main Memory 2. Secondary Memory
1. Main Memory
Store information
Memory Cell 000 001 002 003 ... 999 100 -34.9 A 23
Memory Address
W
8
1. Main Memory
Memory Cell Byte Bit 1 Byte = 8 bits Can be divided into 2 Categories
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
10
Main Memory
Much faster More expensive Volatile (RAM) Slower Less expensive Permanent
11
Secondary Memory
Computer Components
Secondary Memory
Main Memory
Output Devices
12
Retrieve information from memory Calculate Put back results to memory Intel / AMD (Pentium / Athlon)
13
Boot process
Tell user to load and run Program p1 User start using program
Secondary Storage
HW OS p1 USER
14
Programming Language
Machine Language Assembly Language High-Level Language CPU can execute only the machine language
15
2 methods
Interpretation Translation
16
Output
17
Translation Process
Library Linker
Execute Program
Source Program
Output
CPU
Input Data
18
Translators
19
High-Level Languages
Procedural Language
Object-Oriented Language
Functional Language
Lisp Logic Language Prolog
20
Transform a description (word to equation) Difficult (problem is not clear, input, output) Knowledge of problems Equation and formula
21
Science
Programming Strategy
Dont 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
22
Introduction to Pascal
Procedural programming language Developed by Prof.Niklaus Wirth (Switzerland, 1970s) Named in honor to mathematician, Blaise Pascal Most popular -> Turbo Pascal
23
24
Character set Reserved words Identifiers Constants / Variables Statement / Expression Function / Procedure
26
Character Set
Three categories
27
Reserved Words ()
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.
29
Identifiers ()
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 ()
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.
31
Identifier examples
Valid examples
score, count, total score1, count99, total09 score_1, count_99, total_99 myStudentId my_student_id point&score total-number 9points
32
Invalid examples
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.
34