CO1003 - Chapter 1 - Introduction To Computers and Programming
CO1003 - Chapter 1 - Introduction To Computers and Programming
Chapter 1: Introduction to
Computers and Programming
3
Content
p Introduction
p Computer Organization
p Programming Languages
p Programming Tasks
p Data and Algorithms
p Summary
4
Introduction
p Computer Programming
n Computer
à a device that can perform computations and make
logical decisions billions of times faster than human
beings can
n Programming
à The act of writing the programs executable on the
computers to produce intended results
n Program
à A sequence of instructions written in a programming
language to perform a specified task by the computer
5
Introduction
Programs and
Computers Programming their Results 6
Computer Organization
p Hardware: physical components of
computer (including peripherals)
n the keyboard, screen, mouse, hard disk,
memory, DVDs and processing units, …
p Software: a set of machine-readable
instructions that directs a computer's
processor to perform specific operations
[Wikipedia]
n Application softwares
n Operating system
n System softwares 7
Computer Organization -
Hardware
Computer Architecture
9
Programming Languages
p Programming language: a formal language
for writing a computer program as a
sequence of instructions
n C, C++, C#, Java, PHP, Python, …
p Three general types
n Machine languages
n Assembly languages
n High-level languages
à Providing a sequence of instructions that directly
understandable by computers or requiring some
intermediate translation steps 10
Programming Languages –
Machine Languages
C, C++, Java, …
PHP, Perl, …
gcc; g++
Integrated Development Environment (IDE):
Visual Studio; Eclipse; Qt Creator; Code block; Online tool; etc
17
Programming Tasks
p Editor: supports text editing feature for
writing source code
p Preprocessor: preprocesses the source code
with replacing macro, inserting library files
*.h, …
p Compiler: translates the source code into
target machine language
p Linker: links the object code to other library
files
18
Data and Algorithms –
Concepts
p Program
25
Data and Algorithms –
Algorithms - Flowchart
26
Data and Algorithms –
Algorithms - Flowchart
false
<Condition>
true
<Statements>
if Statement
28
Data and Algorithms –
Algorithms - Flowchart
false
<Condition>
true
if-else Statement 29
Data and Algorithms –
Algorithms - Flowchart
switch-case Statement
30
Data and Algorithms –
Algorithms - Flowchart
<initialization>
false
<Condition>
true
<Iteration Value
<Statements>
Modification>
for Statement
31
Data and Algorithms –
Algorithms - Flowchart
false <Statements>
<Condition>
true
true
<Condition>
<Statements>
false
32
Flowchart vs. Pseudo Code?
p Example 2: minNumber = How to add the checking
positiveNumber[1] of n positive numbers?
given n
positive iteration = 2
numbers,
false
iteration <= n
find the
smallest true
false
minNumber =
positiveNumber[iteration]
33
Data and Algorithms –
Algorithms – Real code in C
void main() {
double positiveNumber[10] = {2, 1, 3, 10, 8, 3, 4, 5, 9, 12};
int n = 10;
How to add the checking
double minNumber = positiveNumber[0]; of n positive numbers?
int iteration = 1;
while (iteration < n) {
if (minNumber <= positiveNumber[iteration]) iteration = iteration + 1;
else {
minNumber = positiveNumber[iteration];
iteration = iteration + 1;
}
}
} Pseudo Code vs. Flowchart vs. Real Code in C? 34
Summary
p Concepts related to computer programming
36