Sunteți pe pagina 1din 30

EC201

Fundamental Programming

Unit 1:
Introductory to
Programming
By
Mohd Nasri Bin Hashim
Jabatan Kejuruteraan Elektrik

1.1: Introduction to Programming


Define:
a.Program
- A set of directions telling a computer exactly what to do
b.Programmer
- A person who writes instructions (programs) to make
computer perform a task
c.Programming Language
- Languages for specifying sequences of directions to a
computer

1.1: Introduction to Programming


Types of Programming Languages:
a.Machine Language
- It is computers native language having a sequence of zeroes
and ones (binary). Different computers understand different sequences.
Thus, hard for humans to understand: e.g.0101001...
b.Assembly Language
- It uses mnemonics for machine language. In this each
instruction is minimal but still hard for humans to understand. Eg: ADD,
ADC, MOV
c.High-Level Language
- FORTRAN, Pascal, BASIC, C, C++, Java, etc. Each
instruction composed of many low-level instructions, closer to English. It
is easier to read and understand. Eg: grossPay = basePay +
overTimePay

1.1: Introduction to Programming


Some Well-known Programming Languages:
Language

Description
A structured, general purpose language
developed at Bell Lab. C offers both high
C
level and low level features.
Based on the C languages, C++ offers
object oriented features not found in C.
C++
Also invented at Bell Lab.
An object oriented languages invented at
Sun Microsystems. Java may be used to
Java
develop programs that run over in the
internet, in a web browser.
A Microsoft programming language and
software development environment that
Visual Basic
allows the programmers to quickly create
Windows base application.
Page 4

1.1: Introduction to Programming


Types of Programming (technique):
a. Structured Programming
b. Modular Programming
c. Object-Oriented Programming
a.Structured Programming
- A disciplined approach to writing programs that are clear,
demonstrate correct and easy to modify. A structured program is
one
consisting entirely of three types of logic structures:
1) Sequence Structure
2) Selection Structure
3) Iteration Structure

1.1: Introduction to Programming


Types of Programming (technique):
b. Modular Programming
- 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.1: Introduction to Programming


Types of Programming (technique):
c. Object-Oriented Programming
-To make programs more closely model the way people think about
and deal with the world.
-In the older styles of programming, a programmer who is faced
with some problem must identify a computing task that needs to be
performed in order to solve the problem.
-A set of tools and methods that enable software engineers
-To build reliable, user friendly, maintainable, well documented,
reusable software

1.2: Understanding Problem Solving


Stages in problem solving:
System
requirement
System
analysis

What the requirement needed


Analyze the problem

System design

Create the design of problem


solving

Implementatio
n/coding

Implement the solving

System
testing
Maintenance

Test the solving


Make some maintenance if any
problem

1.2: Understanding Problem Solving


Elements of problem analysis:
a.Input
b.Process
c.Output

1.2: Understanding Problem Solving


Design Tools of problem solving:
a.Flowchart
b.Pseudocode
c.IPO chart (Input-Process-Output chart)
d.Structured Chart

1.2: Understanding Problem Solving


Design Tools of problem solving:
a.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.

1.2: Understanding Problem Solving


Design Tools of problem solving:
a.Flowchart

1.2: Understanding Problem Solving


Design Tools of problem solving:
a.Flowchart
Example
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.2: Understanding Problem Solving


Design Tools of problem solving:
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.
Two type of writing pseudocode
Similar to natural language
Similar to programming language

1.2: Understanding Problem Solving


Design Tools of problem solving:
b.Pseudocode
i. Similar to natural language

1.2: Understanding Problem Solving


Design Tools of problem solving:
b.Pseudocode
ii. Similar to programming language
Example:
Write a program that accept two numbers and display the bigger and
smaller numbers.

1.2: Understanding Problem Solving


Design Tools of problem solving:
b.Pseudocode
iii. Repetition Structure
Example :
Sum 5 numbers entered by user and display the value.

1.2: Understanding Problem Solving


Design Tools of problem solving:
b.Pseudocode
Example :
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

1.2: Understanding Problem Solving


Design Tools of problem solving:
c.IPO Chart
Example :
Display the total and average of three numbers.
INPUT
nom1,nom2, nom3

PROCESS
Total = nom1+nom2+nom3

OUTPUT
- Total
- Average

1.2: Understanding Problem Solving


Design Tools of problem solving:
d.Structured Chart
Example :
Displays the total price of pencils if the price of one pencil is RM0.50
each

1.2: Understanding Problem Solving


Types of error in programming:
a.Syntax Error
A syntax error refers to a flaw made during the initial programming
stage. When a syntax error is encountered during the compilation of a
program, it must be immediately corrected in order for the source code
to be compiled successfully. This type of problem is common when
inaccurate equations are entered into a programming calculator. This
normally occurs when brackets are closed and left open, or specific
characters are omitted

1.2: Understanding Problem Solving


Types of error in programming:
b.Run-Time Error
An error that occurs during the execution of a program. In contrast,
compile-time errors occur while a program is being compiled. Runtime
errors indicate bugs in the program or problems that the designers had
anticipated but could do nothing about. For example, running out of
memory will often cause a runtime error.
c.Logical Error
A logic error is when the program compiles as expected, but runs in
an unexpected way. For instance, say you write a method to sort an
array. It compiles fine, but after you run it the array is still unsorted. This
is a logic error.

Introduction to programming
Common Programming Errors
Error
(bugs)
Syntax Errors

Run-time
Errors

Logic Errors

EC201 Fundamental Programming

Page 27

Introduction to programming
Common Programming Errors
1

Syntax Error

Error occurred during


compilation
normally
due to syntax
:
e
l
p
m
a
Ex problem

Misplaced else.
Declaration sytanx error
Undefined symbol _main in module.
Statement missing in function main()
EC201 Fundamental Programming

Page 28

Introduction to programming
Common Programming Errors
2

Logic Error
Error occurred due to
inappropriate
output.
Programming mistake.
Not detected during
compilation.
EC201 Fundamental Programming

Page 29

Introduction to programming
Common Programming Errors
3

Run-time Error

Error occurred due to wrong user


input.
Users mistake.
System would either display alert
message or hang.

EC201 Fundamental Programming

Page 30

S-ar putea să vă placă și