ITEC1030_Ch02_Introduction to Programming (1)
ITEC1030_Ch02_Introduction to Programming (1)
Department of information
Technology
Basic Computer
Programming
_________________________________________
@ 2024 FTVT Institute All Rights Reserved
Introduction to
Programming
2 Introduction to ICT
Objective
After studying this chapter you will be able to:
• Define the fundamental concepts of programming,
including computer programs, programming, and
programming languages.
• Identify the characteristics and types of programming
languages (low-level and high-level).
• Explain the process of problem-solving in programming,
including steps such as analyzing problems, designing
algorithms, coding, testing, and debugging.
• Apply algorithm design techniques using tools like
pseudocode, flowcharts, and structured charts to solve
basic computational problems.
• Understand program development process, from editing
and compiling to linking and loading.
3
Department of Information AUGUST
Outline
2.1 Introduction to
Programming
2.2 Problem solving and
algorithm design techniques
2.3 Program design and
development process
OF-FTI-ALL -18 4 4
Department of Information AUGUST
1
Introduction to
Programming
5 Introduction to ICT
Discussion
What is Computer
Program ?
6
Department of Information AUGUST
Chapter 2 2.1 Introduction to Programming Computer Programs
What is Programming
?
8
Department of Information AUGUST
Chapter 2 2.1 Introduction to Programming Computer Programming
Computer Programming
is the process of writing, testing,
debugging / troubleshooting, and
maintaining the source code of
computer programs.
Writing computer programs means
writing instructions, that will make the
computer follow and run a program
based on those instructions.
9
Department of Information AUGUST
Chapter 2 1.1 Introduction to Programming Computer Programming
OF-FTI-ALL -18 1 10
Department of Information AUGUST 0
Chapter 2 2.1 Introduction to Programming Computer Programming
Many Aspects of
Programming
• Programming is problem solving
• always trying to make computer do something useful — i.e.,
finding an optimal travel route
• Programming is controlling
• computer does exactly what you tell it to
• Programming is teaching
• computer can only “learn” to do new things if you tell it how
• Programming is creative
• must find a good solution out of many possibilities
• Programming is modeling
• describe salient (relevant) properties and behaviors of a system of
components (objects)
• Programming is abstraction
OF-FTI-ALL -18 1 11
Department of Information AUGUST 1
Chapter 2 2.1 Introduction to Programming Programmer
Programmer
OF-FTI-ALL -18 1 12
Department of Information AUGUST 2
Discussion
What is Programming
Language ?
1
Department of Information AUGUST 3
Programming
Chapter 2 1.1 Introduction to Programming
language
Programming language
• It is a set different category of written symbols
that instruct computer hardware to perform
specified operations required by the designer.
• an artificial language that can be used to control
the behavior of a computer
• A main purpose of programming languages is to
provide instructions to a computer.
• Programming languages have many similarities with
natural languages e.g., they conform to rules for
syntax and semantics, there are many dialects, etc.
1
Department of Information AUGUST 4
Programming
Chapter 2 2.1 Introduction to Programming
language
Some Well-Known
Programming Languages
C++
BASIC Ruby
FORTRAN
Java
Visual Basic
COBOL C#
JavaScript
C Python
1
Department of Information AUGUST 7
Types of
Chapter 2 2.1 Introduction to Programming programming
Types of programming language language
• Available programming
languages come in a variety of
forms and types. Thousands of
different programming languages
have been developed, used, and
discarded.
• Programming languages can be
divided in to two major
categories: 1
Department of Information AUGUST 8
Low-level languages
• Machine language
• Computers only understand one language and that is
binary language or the language of 1s and 0s.
• Binary language is also known as machine language,
one of low-level languages.
• In the initial years of computer programming, all the
instructions were given in binary form.
• Although the computer easily understood these
programs, it proved too difficult for a normal
human being to remember all the instructions in
the form of 0s and 1s.
• Therefore, computers remained mystery to a
common person until other languages such as
assembly language was developed, which were easier
to learn and understand
1
Department of Information AUGUST 9
---A. Low-level languages
• Assembly language
• correspondences symbolic instructions and executable
machine codes and was created to use letters (called
mnemonics) to each machine language instructions to make it
easier to remember or write. For example:
• ADD A, B – adds two numbers in memory location A and B
• Assembly language is nothing more than a symbolic
representation of machine code, which allows symbolic
designation of memory locations.
• However, no matter how close assembly language is to machine
code, computers still cannot understand it. The assembly
language must be translated to machine code by a separate
program called assembler.
• The machine instruction created by the assembler from the
original program (source code) is called object code.
• Thus assembly languages are unique to a specific computer
(machine). Department of Information AUGUST
2
0
---A. Low-level languages
• Assembly language
• The machine instruction created by the
assembler from the original program (source
code) is called object code.
• Thus assembly languages are unique to a
specific computer (machine).
• Assemblers are written for each unique
machine language.
• Although programming in assembly language
is not as difficult and error prone as stringing
together ones and zeros, it is slow and
cumbersome. 2
Department of Information AUGUST 1
B. High-level languages
• The lack of portability between different
computers led to the development of high-level
languages—so called because they permitted a
programmer to ignore many low-level details of
the computer's hardware.
• Further, it was recognized that the closer the
syntax, rules, and mnemonics of the programming
language could be to "natural language" the less
likely it became that the programmer would
inadvertently introduce errors (called "bugs")
into the program.
• High-level languages are more English-like and, 2
Department of Information AUGUST 2
----- B. High-level languages
• High-level languages also require translation to
machine language before execution.
• This translation is accomplished by either a compiler
or an interpreter.
• Compilers translate the entire source code program
before execution.
• Interpreters translate source code programs one
line at a time.
• Interpreters are more interactive than compilers.
• FORTRAN (FORmula TRANs,ator), BASIC (Bingers All
Purpose Symbolic Instruction Code), PASCAL, C, C++,
Java are some exa-ples of high-level languages.
2
Department of Information AUGUST 3
Low level vs High level
• low-level
• provide little or no abstraction, e.g., machine code and
assembly language
• Difficult to use
• Allows to program efficiently and with a low memory footprint
• used for communication with computer hardware
directly.
• Often written in binary machine code (0’s/1’s) directly.
• machine specific or dependent.
• high-level
• closer to human languages
• isolate the execution semantics of a computer architecture
from the specification of the program
• Simplifies program development Department of Information AUGUST
2
4
Why do we need
Chapter 2 2.1 Introduction to Programming
programming?
Why do we need programming?
• The main goal of programming is to make tasks easier
• If we program a task for one time, we can reuse it in many
similar situations, saving time.
• Computer programming will impact the future by creating
even more automated processes requiring less human
interaction.
• Banking from any location is possible only by
programming.
• For example, an online banking website or application
which opens a user portal from which the applicants can
make transactions using a smartphone or computer
• we can save time, energy, and physical work of going to the
bank for every small need.
OF-FTI-ALL -18 2 25
Department of Information AUGUST 5
2
Problem Solving
26 Introduction to ICT
2.2.1 Introduction Problem
Chapter 2 2.2 Problem Solving Introduction
Problem Solving
Solving
• Today, computers are all around us.
• We use them for doing various tasks in a faster
and more accurate manner.
• For example, using a computer or smartphone, to
book airplane tickets online.
• Computers are used for solving various day-to-
day problems
• Problem solving is an essential skill that a
student should know.
OF-FTI-ALL -18 2 27
Department of Information AUGUST 7
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving
• Problem solving is the process of transforming the
description of a problem into the solution by using
our knowledge of the problem domain and by
relying on our ability to select and use appropriate
problem-solving strategies, techniques, and tools.
• Problem solving, or breaking down the solution to a
problem into sequential steps is by far the most difficult
part of computer programming.
• A problem is an undesirable situation that prevents the
organization from fully achieving its purpose, goals and
objectives.
• Or problem can also be defined as the gap between the
existing and the desired situation where problem
solving will try to fill this gap.
2
Department of Information AUGUST 8
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving
OF-FTI-ALL -18 2 29
Department of Information AUGUST 9
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving
so
• Problem solving is the process of
• Identifying a problem
• Developing an algorithm for the identified
problem
• Implementing the algorithm to develop a
computer program.
OF-FTI-ALL -18 3 30
Department of Information AUGUST 0
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving
OF-FTI-ALL -18 3 31
Department of Information AUGUST 1
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving
2.2.2 Steps of Problem Solving
• When problems are straightforward and
easy, we can easily find the solution.
• A complex problem requires a methodical
approach to find the right solution.
• Problem solving begins with the precise
identification of the problem and ends with
a complete working solution in terms of a
program.
OF-FTI-ALL -18 3 32
Department of Information AUGUST 2
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving
Algorithm
• It is essential to devise a solution before
writing a program code for a given problem.
• The solution is represented in natural
language and is called an algorithm.
• Imagine an algorithm is like a very well-
written recipe for a dish, with clearly defined
steps that, if followed, one will end up
preparing the dish.
OF-FTI-ALL -18 3 35
Department of Information AUGUST 5
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving
Step 3: Coding
• The algorithm need to be converted into
the format which can be understood by the
computer to generate the desired solution.
• Different high level programming languages
can be used for writing a program.
• It is equally important to record the details
of the coding procedures followed and
document the solution.
OF-FTI-ALL -18 3 36
Department of Information AUGUST 6
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving
3
Department of Information AUGUST 9
Chapter 2 2.2 Problem Solving Algorithm
4
Department of Information AUGUST 0
Chapter 2 2.2 Problem Solving Algorithm
5. Effectiveness
•All operations within the algorithm should be basic enough to be
executed in a finite amount of time using available resources.
6. Correctness
•The algorithm should correctly solve the problem for all defined inputs
and produce the expected outputs.
7. Efficiency
•The algorithm should make optimal use of resources like time (time
complexity) and space (space complexity). It should aim for minimal
computational and memory usage.
8. Robustness
•The algorithm should handle unexpected or invalid inputs gracefully,
providing appropriate feedback or handling mechanisms.
Techniques
• There are three commonly used tools to help to
document program logic (the algorithm). These
are
1. flowcharts,
2. structured chart, and
3. Pseudocode.
• We will use the three methods here.
• Generally, flowcharts work well for small
problems but Pseudocode is used for larger
problems.
OF-FTI-ALL -18 4 44
Department of Information AUGUST 4
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
1. Pseudocode
• Is an artificial and informal
language that helps
programmers develop algorithms
• Allows the designer to focus on the
logic of the algorithm without being
distracted by details of language
syntax
• text-based" detail (algorithmic)
design tool 4
Department of Information AUGUST 5
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
4
Department of Information AUGUST 9
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Control Structures
• programs could be written in terms
of 3 structures:
• Sequence – which instruction should be
done next?
• Selection – select between options
• Repetition – repeat an action while a
given condition stays true
5
Department of Information AUGUST 0
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Sequence: Executing instructions one after another as they
appear in the program.
.
Start
Input first
num
Input second
num
Sum=first num + second
num
avg=sum/2
Output sum
Output avg
End
5
Department of Information AUGUST 1
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Selection
• Diamond symbol (decision symbol)
• Indicates decision is to be made
True print
• Contains an expression that can be true
Grade>=60 passed
or false
• Test the condition, follow appropriate
path False
Single Selection (if)
If grade >=60
print passed
Double Selection (if-else)
• If grade >=60 :
passed False True
Grade>=60
else: Failed ? passed
failed
5
Department of Information AUGUST 2
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Selection (continued)
• Multiple Selection (switch)
If the light is ... Light True
Red? Stop
red -> stop
False
green -> go Light
True
Go
yellow -> slow down Green?
False
True
Light Slow
Yellow? Down
False
5
Department of Information AUGUST 3
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Repetition
Teaching a baby to
Counter = 1
count from 1 to 10:
counter = 1
Add 1
if counter <= 10:
to counter
increment counter
CounterTrue print counter number
Print
≤ 10?
counter
False
5
Department of Information AUGUST 4
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
3. Structure Chart
• The structure chart is an important
technique that helps the analyst
design the program for the new
system.
• There are three components in the
structured chart: modules,
connections between modules, and
communication between modules.
5
Department of Information AUGUST 5
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Structure Chart Example
• A Simple Sequence Problem
We want to develop an algorithm (a step by step
process) for a program to calculate the sum and
average of two numbers entered by the user of the
program.
5
Department of Information AUGUST 6
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Cont…
• The structure chart shows the relationship
among the various components of the program.
• The top level is a general description of the
problem to be
• Solved where the lower levels show all the detail
or specifics of the solution.
• NOTE: The second level of a structure
chart attempts to break the solution into
three basic parts – an input module, a
processing module and an output module.
5
Department of Information AUGUST 7
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Examples
5
Department of Information AUGUST 8
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 1
5
Department of Information AUGUST 9
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution 1 for example 1
(simple)
6
Department of Information AUGUST 0
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution 1 for example 1 (More
technical)
6
Department of Information AUGUST 1
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution 1 for example 1 (Using Flow
chart)
6
Department of Information AUGUST 2
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 2
• Write an algorithm which calculates the average
exam grade for a class of 5 students.
What are the program inputs?
the exam grades
Processing:
Find the sum of the grades;
count the number of students; (counter controlled)
calculate average grade = sum of grades / number of students.
What is the program output?
the average exam grade
6
Department of Information AUGUST 3
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 2 (More
technical)
Pseudocode
6
Department of Information AUGUST 4
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 2 (Using
flow chart)
Flowchart
6
Department of Information AUGUST 5
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 3
6
Department of Information AUGUST 6
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 3
(simple Pseudo code)
6
Department of Information AUGUST 7
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 3 (More technical
Pseudo code and flowchart)
6
Department of Information AUGUST 8
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 4
6
Department of Information AUGUST 9
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 4
(Pseudo code)
7
Department of Information AUGUST 0
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 4
(Using flow chart)
7
Department of Information AUGUST 1
3
Program
development
process
72 Introduction to ICT
Mechanics of
Chapter 2 2.3 Program development process Creating a program
(C++ IDE)
OF-FTI-ALL -18 7 73
Department of Information AUGUST 3
Chapter 2 2.3 Program development process Introduction to C++
7
Department of Information AUGUST 4
Chapter 2 2.3 Program development process C++ History
7
Department of Information AUGUST 5
Chapter 2 2.3 Program development process C++ IDE
OF-FTI-ALL -18 7 77
Department of Information AUGUST 7
Chapter 2 2.3 Program development process C++ IDE
---Edit:
• this is accomplished with an editor program.
• The programmer types C++ statements with
the editor and makes corrections if necessary
• The programs source file is then stored on
secondary storage device such as a disk with a
“.cpp” file name.
• After the program is edited, C++ is principally
compiled in three phases: preprocessing,
translation to object code, and linking
• the last two phases are what is generally
thought of as the "compilation"
OF-FTI-ALL -18
process).
Department of Information AUGUST
7
8
78
Chapter 2 2.3 Program development process C++ IDE
---Preprocess:
• In a C++ system, a preprocessor program
executes automatically before the compiler’s
translation phase begins.
• The C++ preprocessor obeys command called
preprocessor directives, which indicate that
certain manipulations are to be performed on the
program before compilation.
• The preprocessor is invoked by the compiler
before the program is converted to machine
language.
• The C++ preprocessor goes
OF-FTI-ALL -18over
Department the program
of Information AUGUST
7
9
79
Chapter 2 2.3 Program development process C++ IDE
---Compile:
• Then, the C++ compiler translates the program
code.
• The compiler converts source code to object
code
• The compiler may be a true C++ compiler
which generates native (assembly or
machine) code.
• The outcome may be incomplete due to the
program referring to library routines which are
not defined as a part of the program.
80
•
OF-FTI-ALL -18 8
Department of Information AUGUST 0
Chapter 2 2.3 Program development process C++ IDE
---Linking:
• C++ programs typically contain references to
functions and data defined else where, such as
in the standard libraries.
• The object code produced by the C++ compiler
typically contains “holes” due to these missing
parts.
• A linker links the object code with the code for
the missing function to produce an executable
image (with no missing pieces).
• Generally, the linker completes the object code
by linking it with the object
OF-FTI-ALL -18code
Department of any library
of Information AUGUST
8
1
81
Chapter 2 2.3 Program development process C++ IDE
---Loading:
• the loader takes the executable file from
disk and transfers it to memory.
• Additional components from shared
libraries that support the program are
also loaded.
• Finally, the computer, under the control
of its CPU, executes the program.
• In practice all these steps are usually
invoked by a single command and the
user will not even see the intermediate
OF-FTI-ALL -18
Department of Information AUGUST
8
2
82
Chapter 2 2.3 Program development process C++ IDE
OF-FTI-ALL -18 8 83
Department of Information AUGUST 3
OF-FTI-ALL -18 8 84
Department of Information AUGUST 4