Introduction
In the beginning..
Lecture Overview
Computer
system
Processed
information
Data units
Output
Memory
Contains processor,
memory, buses, etc.
Keyboard and
mouse (input)
Software
Software is a written program that directs the
operation of computer
Related terms:
Software (1/4)
Program
Execution
Programming language
Major flavors
Software (2/4)
Program
Execution
Programming language
Major flavors
Example: 0001001101101110
[ CS1010E AY1112S1 Lecture 1 ]
Software (3/4)
Program
Execution
Programming language
Major flavors
language instructions.
Example: ADD A, B, C
10
Software (4/4)
Program
Execution
Programming language
Major flavors
11
Programming Languages
On or Off (encoded as 1 or 0)
known as binary values
Multiply 3.14159
with 1.23!
????
010111000111?
12
Programming Languages
Natural
Language
Multiply 3.141
with 1.23
High Level
Language
Assembly
Language
Machine
Language
res = 3.141*1.23;
0110111011010
1101010101
0110001..
Ease of expression
[ CS1010E AY1112S1 Lecture 1 ]
13
Translating a program
Translator
Compiler
Interpreter
14
15
Analysis
Design
Implementation
Testing
16
Purpose:
What to do:
17
Purpose:
What to do:
18
Purpose:
What to do:
19
Purpose:
What to do:
20
Analysis
Write algorithm
Design
Produce code
Implementation
Testing
Rethink as
appropriate
21
Input
Algorithm
Output
22
Algorithms
Characteristics of an algorithm:
1.
2.
3.
4.
23
Euclidean algorithm
where 0 r < B
24
Algorithm: Observations
Sequential:
Repetition:
Selection:
25
Version 1
Declare variables sum, count and max.
First, you initialise sum, count and max to zero.
Then, you enter the input numbers, one by one.
For each number that you have entered, assign it to num and
add it to the sum.
Increase count by 1.
At the same time, you compare num with max. If num is larger
than max, let max be num instead.
After all the numbers have been entered, you divide sum by the
numbers of items entered, and let ave be this result.
Print max and ave.
End of algorithm.
A better version in
next slide
26
Version 2
sum count 0
max 0
27
start
Flowchart
Process box
sum count 0
max 0
Yes
Decision box
end of
input?
No
ave sum/count
increment count
sum sum + num
No
Yes
max num
No
end
28
A possible algorithm:
num1
Variables used:
num1
num3
ave
num2
num2
num3
total
ave
29
Variables used:
n
count
ans
// Display answer
print ans
30
31
// step 1: input
// step 2: compute
// step 3: output
32
33
Exercise: Palindrome