You are on page 1of 50

DEC20012 Programming

Fundamentals

CHAPTER 1:
INRODUCTORY TO
PROGRAMMING

By : Wan Roslina binti Wan Musa


JKE, POLISAS
DEC20012

2 COURSE SYNOPSIS

 PROGRAMMING FUNDAMENTALS course provides


the skills necessary for the effective of application of
computation and computer programming in engineering
applications. Students will develop their programming
skills through a variety of assignments and labs and by
reviewing case studies and example programs. The
learning outcome is proficiency in writing small to
medium programs in a procedural programming
language
DEC20012

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

1.1: The Programming Language


5

How human and computer


interact :
DEC20012
1.1: The Programming Language
6

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

 The lowest level of language.


 Uses 1’s and O’s / binary digits to represents data and instructions
 Examples: 0 represents “off” and 1 represents “on”.
 The only language that the computer could understand (does not require
translator).
1.2: Types of Programming
16 Assembly Language

 Known as symbolic language.


 It uses mnemonic codes - a symbol chosen to help user to remember
 replace “0” and “1”
 For example, A represented ADD and S represented SUM
 Computer does not understand the language so it needs an assembler to
translate the program to machine language.
1.2: Types of Programming
17 High Level Language

 Instruction is written as a series of English-like words.


 Translator (Compiler/Interpreter) is needed to translate high level
language to machine language.
 It is Machine-Independent. The program can be written and executed
on any computer.
 Example: FORTRAN, Pascal, BASIC, C, C++, Java, etc.
1.2: Types of Programming

18 Some Well-known Programming Languages:


1.3: Structure of Programming Methodology

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:

 is a software design technique that increases the extent to which


software is composed from separate parts, called modules.
 Execution of a program begins in the main function.
 The main function can call other functions:
a. Functions defined in the same file.
b. Function defined in other files or libraries
 Functions are also referred to as modules
 A module is a set of statements that performs a task or computes a value
1.2: Structure of Programming Methodology

22 c. Object Oriented Programming:

 refers to a special type of programming approach that combines data


with functions to create objects.
 the objects have relationships with one another.
 One of the earliest OOP languages is Smalltalk.
 Java, Visual Basic and C++ are examples of popular OOP languages.
 uses sections in a program to perform certain tasks.
 splits the program into objects (small programs) that can be reused into
other programs.
 Each object or module has the data and the instruction of what to do with
the data in it. This can be reused in other software .
 is decomposed into a network of collaborating objects. An object
represents a thing or concept
1.2: The Design Tools

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

“Algorithm is not the computer code.


Algorithm are just the instructions which gives
clear idea to write the computer code”
29 b. Pseudocode
 Pseudo code is an abbreviated version of actual computer code.
 When the pseudo code is completed it can be easily translated
into any computer language.
 Artificial and informal language
 Helps programmer to plan algorithm
 Not an actual programming language
 Each line of code represent a step/process.
30 b. Pseudocode
 Example of Pseudocode
The pseudo code below is to find the volume of a box if the
length, width and height are given. Write the program based on
the pseudo code below..

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

Calculate Volume= Length*Width*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

Flowline – Used to connect symbols


and indicate the flow of logic.

TERMINAL – Used to represent the


beginning (Start) or the end (End) of a
task.

PROCESS – Used for arithmetic


and data-manipulation operations.
35 c. Flowchart
Flowchart Symbols

Flowchart Symbols
INPUT/ OUTPUT – Used for input
and output operations, such as
reading and printing.

DECISION – Used for any logic or


comparison operations. The path chosen
depends on whether the answer to a
question is “true” or “false”
36 c. Flowchart
Flowchart Symbols

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 This is a positive number Print This is a Negative Number

 
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!!

You might also like