CHAPTER 1 Introductory To Programming
CHAPTER 1 Introductory To Programming
CHAPTER 1 Introductory To Programming
Fundamentals
CHAPTER 1:
INRODUCTORY TO
PROGRAMMING
2 COURSE SYNOPSIS
3 COURSE LEARNING
COUTCOMES
Upon completion of this course, students should be able to:
CLO1 :
apply knowledge of basic concepts and fundamentals of structured
programming in solving a variety of engineering and scientific
problems using a high level programming language ( C3 , PLO 1 )
CLO2 :
build programs written in C language for assigned mini project
during practical work sessions ( P4 , PLO 5 )
CLO3 :
demonstrate continuous learning skill in independent acquisition of
new knowledge and skill in developing a mini project ( A3 , PLO
12 )
DEC20012
4 COURSE CONTENT
1.0 Introductory to Programming
1.1 Remember programming language
1.2 Remember definition and types of programming
1.3 Understand types of programming and structure programming
methodology
1.4 Remember algorithm, flowchart and pseudocode
1.5 Understand algorithm, flowchart and pseudocode
1.6 Apply algorithm, flowchart, pseudocode and analyse problem
DEC20012
Programming Language
Definition:
• Is a language that is used for writing programs.
• A set of rules and reserved words (keywords) that can
be used to tell a computer what are the operations to be
done.
• An artificial language composed by a fixed vocabulary
and set of rules is used to create instructions for the
computer to follow.
DEC20012
1.1: The Programming Language
C Programming
designed in 1972 by Dennis Ritchie as a tool to develop
UNIX operating system, one of the operating system
today.
Two advantages of C are:
a) Transportable language. User can write C in a
computer then it is compiled to allowed it to run in
another computer.
b) It has both features in high-level and low-level
language at the same time.
7
DEC20012
1.1: The Programming Language
C Programming
in low-level, C allows user to access memory location
and also influence data allocation in CPU register.
C also supports Boolean operation such as shift that can
be used in arithmetic operation and graphic operation.
8
DEC20012
1.1: The Programming Language
C Programming
In high-level, C allows memory management. It also allows
higher to lower level translation.
C also allows structure-coding, supports numeric types
and provides set of instructions.
C’s implementation is provided with large library function
from the function in UNIX.
The Library provides memory, file management and etc.
9
1.1: The Programming Language
10 Structure of program code in C:
1.1: The Programming Language
11 Sample of C Program
Example 1
Write a program that can accept a three integer data entered by the user. Get the average
number and finally show the numbers and average numbers
1.1: The Programming Language
12 Sample of C Program
Example 2
The program code below is to find the volume of a box if the length, width and height are
given.
1.2: The Definition of Programming
13 Definition Of :
Program:
A set of step-by-step instructions that directs a
computer to perform a specific task and to
produce the required results.
Programming:
Programming is a process of designing/ creating
a program.
Programmer:
Programmer is a person who writes the
program.
1.2: Types of Programming
14 Types of Programming Languages
a. Machine languages
b. Assembly languages
c. High Level languages
1.2: Types of Programming
15 Machine Language
19
Structured Programming
Modular Programming
Object-Oriented Programming
1.2: Structure of Programming Methodology
20 a. Structured Programming:
takes on the top-to-bottom approach.
is based around data structures and subroutines.
splits the tasks into modular forms - makes the program simpler and easier
to read with less lines and codes.
type of program that accomplishes certain tasks for a specific reason.
For example, invoice printers use structured programming,
which has clear, correct, precise descriptions.
decomposed into a hierarchy of processes.
A process in this context is a body of code, typically a function or
subroutine, that takes some input and manipulates it to produce an
output.
A process may be composed of other, more specialized processes, i.e., it
may be a function that calls other functions.
1.2: Structure of Programming Methodology
21 b. Modular Programming:
Design Tools
Algorithm
Flowchart
Pseudocode
24 a. Algorithm
A specific set of instructions for carrying out a procedure or
solving a problem.
Usually with the requirement that the procedure terminate at
some point.
Specific algorithms sometimes also go by the name method,
procedure, or technique.
Step by step procedure designed to perform an operation, and
which (like a map or flowchart) will lead to the sought result if
followed correctly.
Algorithms have a definite beginning and a definite end, and a
finite number of steps.
a. Algorithm I = INPUT – num1,num2
25
P = PROCESS- total=num1+num2
O = OUTPUT - total
Example of Algorithm
Write an algorithm to add two numbers entered by user.
I = INPUT – num1,num2
26
P = PROCESS- total=num1+num2
O = OUTPUT – total
ALGORITHM:
Step 1: START
Step 2: DECLARE num1, num2,total
Step 3: READ num1,num2
Step 4: total=num1+num2
Step 5: DISPLAY total
Step 6: STOP
27 a. Algorithm
Example of Algorithm
Write an algorithm to find the largest among three different
numbers entered by user.
28 a. Algorithm
START
INPUT length of the box
INPUT width of the box
INPUT height of the box
Volume = Length x Width x Height
DISPLAY volume of the box
END
31 b. Pseudocode
Pseudocode Program
32 b. Pseudocode
Pseudocode Flowchart
START
Input Length
Input Width
Input Height
Display Volume
END
33 c. Flowchart
Graphic representation of algorithm is known as flowchart
which consists of geometric symbols.
The symbols are connected by line of arrows called flow
lines.
The shape of the symbol indicates the type of operation
that is to occur.
Flow from the top of the page to the bottom.
34 c. Flowchart
Flowchart Symbols
Flowchart Symbols
INPUT/ OUTPUT – Used for input
and output operations, such as
reading and printing.
Flowchart Symbols
CONNECTOR – Used to join
different flowline in the same page.
OFFPAGE CONNECTOR –
Used to indicate that the flow chart
continues on different pages.
37 c. Flowchart
Advantages of Flowchart:
A good way to communicate the details of a task or
processes to others.
It presents the data flow.
It provides a clear overview of the entire program and
problem solution.
It is an important tool for planning and designing a new
system.
38 c. Flowchart
Disadvantages of Flowchart:
Some tasks are difficult to represent using a flowchart.
If an alteration is made the flowchart may need to be
redrawn
People need to understand what the symbols mean.
Flowcharts consumes time and it is laborious to draw with
proper symbols.
39 c. Flowchart
Example of Flowchart:
Each symbol represents the
type of task and it’s content
describe the task.
The flow line represents the
connection and direction of the
task flow
There must always be ONE
start point and ONE end point
Flowcharts provide clear
overview of the task and flow
of the program.
40 c. Flowchart
Example of Flowchart (Sequence Structure)
Problem :
“A program can accept three integer values entered by
the user. Calculate the average and finally show the
average value”
STEP 1: Draw a flowchart from the given problem
STEP 2 : Write a program based on the flowchart
41 c. Flowchart
Example of Flowchart (Sequence Structure)
Step 1: Draw a flowchart from the given problem
42 c. Flowchart
Example of Flowchart (Sequence Structure)
Step 2: Write a program based on the flowchart
43 c. Flowchart
Example of Flowchart (Selection Structure)
Problem :
“A program can accept an integer data entered by the
user. Determine either the input value is positive,
negative or zero”
STEP 1: Draw a flowchart from the given problem
STEP 2 : Write a program based on the flowchart
44 c. Flowchart
Example of Flowchart (Selection Structure)
Step 1: Draw a flowchart from the given problem
START
Enter 1 number
No No
Number > 0 Number < 0
Yes Yes
Print The number is zero
END
45 c. Flowchart
Example of Flowchart (Selection Structure)
Step 2: Write a program based on the flowchart
46 c. Flowchart
Example of Flowchart (Looping Structure)
Problem :
“Write a program to wish HAPPY BIRTHDAY and
it will keep wishing repeatedly based on user’s age
that have been entered by the user”
STEP 1: Draw a flowchart from the given problem
STEP 2 : Write a program based on the flowchart
47 c. Flowchart
Example of Flowchart (Looping Structure)
Step 1: Draw a flowchart from the given problem
48 c. Flowchart
Example of Flowchart (Looping Structure)
Step 2: Write a program based on the flowchart
49
DATA TYPES:
1. int %d (nombor bulat)
2. float %f (nombor perpuluhan)
3. char %c (huruf)
4. char %s (perkataan)
50
Thank You!!