Вы находитесь на странице: 1из 20

2/17/2011

1.1.1 Term

1.0 Introduction To Programming


programme

1.1 Introduction concepts Programming


programmer
language

c) A programming language
 is set of instructions that can be used to
Program: construct a program. A notation for
 A set of step-by-step instructions that directs a computer to
perform a specific task and to produce the required results. writing programs, which are specifications
of a computation or algorithm.
Programming:
 Programming is a process of designing/ creating a program.  is a language designed to describe a set of
consecutive actions to be executed by a
Programmer: computer. A programming language is
 Programmer is a person who writes the program.
therefore a practical way for us (humans)
to give instructions to a computer.

1
2/17/2011

1.1.2 Various types of Programming 1.1.3 (i) Machine language


Languages
 There are three basic types of
 The lowest-level programming language
programming languages.  Machine languages are the only languages
understood by computers.
 While easily understood by computers,
machine languages are almost impossible for
humans to use because they consist entirely of
numbers.
 Expressed in binary form, an instruction might
be 0111010110110011. Very difficult to use.
Lowest level of computer languages.
 For example, a program written in Apple PC cannot
be run in IBM PC

ii) Assembly language

 Second level of language.An assembler  English-like abbreviations representing


translates assembly language. elementary computer
 operations (translated via assemblers)
 It was developed to replace "0" and "1" used
in Machine Language.  Example: C++, C , FORTH

 Machine languages consist entirely of


numbers and are almost impossible for
humans to read and write.Takes a long
time to write programs

2
2/17/2011

1.1.4 Structured Programming


iii) High-level language Languages
 Instruction is written as a series of English- Definition of Structured Programming
like words.  Structured programming can be defined as a
 Translator (Compiler/Interpreter) is needed Software application programming technique that
follows a top down design approach with block
to translate high level language to machine oriented structures.
language.  It support loop such as while, do-while and for.
 It is Machine-Independent.The program can
be written and executed on any computer.  Structured programming
 E.g. Fortran, COBOL, SQL, PROLOG, C

 The most popular structured programming


languages include C,C++, Ada, and Pascal.

 Codes similar to everyday English


 Use mathematical notations

Example: if (x < 10) {


printf(“too low, ry again\n”);
Scanf(“%d”,&x);
}

3
2/17/2011

c. Object-Oriented Programming
b) Modular programming
Languages
 is about relation between the data and the code
 Programming paradigm based on data types. operating on the data (or data operating on the
 An object stores a data type value; variable name code).
refers to object.
 is a programming paradigm that uses "objects" –
 A programming style that brakes down program
functions into modules, each of which accomplishes data structures consisting of data fields and
one function and contains all the source code and methods together with their interactions – to
variables needed to accomplish that function. design applications and computer programs.
 Modular programming is a solution to the problem of Programming techniques may include features
very large programs that are difficult to debug and such as data abstraction, encapsulation,
maintain. By segmenting the program into modules modularity, polymorphism, and inheritance. Many
that perform clearly defined functions, you can
determine the source of program erros more easly. modern programming languages now support
OOP

 is one the newest and most powerful paradigms.


In object- oriented programs, the designer
specifies both the data structures and the types
of operations that can be applied to those data
structures.

 This pairing of a piece of data with the operations


that can be performed on it is known as an
object. A program thus becomes a collection of
cooperating objects, rather than a list of
instructions.

 Objects can store state information and interact


with other objects, but generally each object has
a distinct, limited role.

4
2/17/2011

 An object stores a data type value;  The most popular object-oriented


variable name refers to object. programming languages include Java, Visual
 Object-oriented programming (OOP) is a Basic, C#, C++, and Python.
programming paradigm based on data
types.  Object-orientated programming
languages, such as SmallTalk and
HyperTalk, incorporate modular
programming principles

1.1.5 Comparison between the Structured programming is as


following types of programming: follows:

a) Structured programing
--Program start
 The main advantage for structured var
programing is that it make input easy, and var
var
also it is better to use because it does not
function { ... }
merges the data we stored in strings and function { ... }
variables, sometime it happens that we get function { ... }

merged data if we don't use structured data. main { ... }


--- Program End
And it also make easy to manage variables.
You have units of code, which operate on variables, and are
called in reference to those variables, to follow a structure
acting on those variables.

5
2/17/2011

Modular Programming - Need


b) Modular programming and Approach
 -A detailed process of problem solving  Typical industry programming projects
-Break a large problem into several consist of thousands of lines of code or
smaller more
 Sub-sections are solved separately by  Analogous approaches: manufacturing a
observing that all these small modules to spacecraft, or a car Manufacture individual
solve the whole problem of the origin components, test separately
 Assemble into larger components,
integrate and test

Advantages of Modular
Modular Programming -
Programming
Process
 Manageable: Reduce problem to smaller, simpler,
humanly comprehensible problems
 Divisible: Modules can be assigned to different
teams/programmers
 Enables parallel work, reducing program
development time
 Facilitates programming, debugging, testing,
maintenance
 Portable: Individual modules can be modified to
run on other platforms
 • Re-usable: Modules can be re-used within a
program and acrossprograms

6
2/17/2011

An Example of Code that Doesn't Use A Simple Example of Modular


Modular Programming Programming
A simple example of repeated code can be seen in: The aim of the programmer is now to ensure that code is reused as much as possible. They do this by identifying the code that can be place
separate functions and subroutines:
PI = 3.14159265358979
R= 1
PI = 3.14159265358979
C = 2 * PI * R
function circumference (R)
A = PI * R * R
circumference = 2 * PI * R
wscript.echo "Radius " & R & " Circumference " & C & " Area " & A
end Function
R= 2
function area (R)
C = 2 * PI * R
area = PI * R * R
A = PI * R * R
end function
wscript.echo "Radius " & R & " Circumference " & C & " Area " & A
sub print_details (R)
R= 3
C = circumference (R)
C = 2 * PI * R
A = area (R)
A = PI * R * R
wscript.echo "Radius " & R & " Circumference " & C & " Area " & A
wscript.echo "Radius " & R & " Circumference " & C & " Area " & A
end sub
R= 4
print_details 1
C = 2 * PI * R
print_details 2
A = PI * R * R
print_details 3
wscript.echo "Radius " & R & " Circumference " & C & " Area " & A
print_details 4

Here the same functionality is repeated but does works (as can be seen in figure 1). However, the programmer can work more ef ficiently
by using modular programming. The output is the same as before (as can be seen in figure 2), but this time the chance of the operation of the script being altered due to a
typing error is greatly reduced, and if there is an error then the task of correcting it is made much simpler. The programmer can also
use the functionality throughout their application without worrying about having to rewrite the code, thereby improving the e fficiency
of both the code and their time.

c)Object oriented Why Object Oriented Language?


 - fourth-generation language is object 
oriented. Reusability-Cepatkan project
- Programmers will more tend to think of - Improve the quality of
the objects involved - Easily adjusted
the problem and the relationships - Flexible
between objects. - Easy maintenance
-Examples of programming languages are - Reduce the risk for complex projects
C + + Java

7
2/17/2011

c) Object oriented
 is as follows:
 Variables can be objects, which have their
--- Program Start
object { own data and functions. Think like C and
var
var structures, except structures can have
function { ... }
function { ... } functions "in them" which operate
function { ... }
} specificly on their own data.
var
var
function { ... }
main { ... }
--- Program end

Example 1: Object-oriented
Problem Solving Approach
Step 1: Problem Identification - Compute Step 2: Object Identification
the sum of two numbers and print out - Identify objects needed to solve the
the result. problem.
Num1 - first number (object).
Num2 - second number (object).
Sum - result of the addition of the two
numbers (object).

8
2/17/2011

Step 3: Message Identification Step 4: Object-message sequences - Following


- Messages needed to send to objects. is the object-message sequence to solve the
problem.
+ aNum - This is the message sent to the (Num1 + Num2)print The message + with a
receiver object with an parameter aNum. parameter Num2 (an object), is sent to the
The result of this message is the value (a object Num1.
numeric object) of the total sum of the The result of this is an object (Num1 +
receiver object and aNum. print - a message Num2), which is sent the message print. The
that displays the value of the receiver object. parentheses are included to avoid any
ambiguity as to which message should be
activated first.

1.2.1 Stages of Problem Solving


Note: The sequence of Smalltalk evaluation
is from left to right unless is specified by
parentheses ( ). For example:
2 + 3 * 4 is 20
while
2 +(3 * 4) is 14

9
2/17/2011

The steps in programming: 1.2.2 Elements of problem analysis



1-Definitions and identify problems
- Identify and understand the problems to
be solved
i. Read the questions and identify and
understand the requirements of the question PROCESS

ii. For the analysis to determine the


problem with three main areas:
* Input required
* OUTPUT issued
* PROCESS determine the formula
to get the output from a given input

3. Design a flow chart (design


2 - Planning variables
software)
 variable is a reference to a memory  Better known as the process of
location designing algorithms
 Variables with a specific type of data to  algorithm - list of measures to solve
determine the memory size provided problems
 All variables must be used in the program  Created before the actual program coding
prior diishtiharkan to make sure the solution method
correct the problem that is use

10
2/17/2011

There are two ways to write the


Pseudo code
algorithm:

i. Pseudo code Example: Changing a bulb is burned
-Steps problem solving
-Written to spoken language daily Start
Removing the bulb is burned
Replace with new bulb
End

Contoh:Mengira harga
Is it sufficient for the
bayarbagi buku
implementation of the computer?

Example: Changing a bulb is burned (details)
 Start
Place the ladder in the position of the bulb burns
Choose a suitable lamp
Take the stairs up to the light bulb that burns
Turn the bulb counterclockwise and take out the
bulb
Fit the new bulb in place proper
Turn the bulb clockwise
Down the stairs
Place the back stairs
End

11
2/17/2011

4-Writing program 5-Testing & debugging program


 - Represents the implementation phase in 
which the code was written and typed into -The program that has been built to test /
the computer run (run) to ensure
- The program should follow the syntax output produced is correct and meet the
correctly written on the appropriate needs of users
programming language - Menyahsilap (debugging) --- the program
- Some programming languages: BASIC, is tested with real data
COBOL, FORTRAN, C + +,Visual BASIC
-There is a possibility of erroneous
and other.
output (error) could result from a
 Problems ---- Pseudo Code /flow chart -----
program written
program

The types of programming errors


i) Syntax Error / encoding
 when programmers fail to follow the rules governing how
the instruction should be written. iii. Time Error
 Example: wrong spelling of the WRITE command. The
computer will print a diagnostic message. Due to data entry is not in accordance
 After all syntax errors corrected or removed compiler can
understand and translate the program.
with the instructions written in
programming
ii) Logic errors
 error occurred from instruction sequences that are not
correct.
 It might be the error in logic programming.
 Instruction means may be in conflict.
 Example: the programmer should write direction READ but
it write WRITE

12
2/17/2011

6-Documentation Program The documentation includes:


 Type of problem or the specific requirements
 If the output properly certified and meet
consumer needs of the appropriate
- at this stage is to prepare a report for  Description of inputs, outputs, constraints and
reference and for the updates in the formulas for problem
future  A tool used logic---- flow chart or pseudo
- Facilitate the programmer to understand code
the design and programmable logic  Example output of the program was
implemented (executed) using the test data
 The steps or guidelines for using the program

1.2.4 Determine input, process and


output for a given problem
Problem analysis
 Understand, identify and define problems. Problem 1
 Determine the input requirements, Create a program that will accept three numbers as input
process and output (IPO) from the user. Find the average number and the third show -
the three numbers together with the average value.
 Provide IPO
Analysis of problems
Input - 3 numbers
Process - 1. Add 3 numbers
2. 3 Divide the total number to 3
Output - 3 and the average number

13
2/17/2011

answers Problem 2

Given the value of x = 10 and the value of


a = 12, find the equation of state revenue
under
y = 2x + a -6

1.2.5 DESIGN TOOL

 Problem analysis  It is a framework or flow that shows the


1) Input: steps in problem solving.
the value of x = 10
and the value of a = 12  Methods to design a program:
2) the formula / process:  Flowchart
y = 2x + a - 6  Pseudocode
3) output:  IPO Chart(input-process-output
the value of y chart)
 Structure Chart

14
2/17/2011

a) Flowchart

 A graphical representation of data,


information and workflow using certain
symbols that are connected to flow lines
to describe the instructions done in
problem solving.

 It shows the flow of the process from


the start to the end of the problem
solving

Explanation of basic
flowchart symbol:

15
2/17/2011

Cont…Explanation of basic There are few additional symbols of flowchart


used in a complicated program: GOSUB and
flowchart symbol: RETURN. It’s usually used in a big program.

Example Flowchart:
Flowchart to calculate the total of fine for late
returning of library books.

16
2/17/2011

b)Pseudocode
 Steps in problem solving that is written half in
programming code and half in human language. Example:

 For example, some part uses C language code and


some part uses Malay or English language. START
Total=0, Average=0
 Advantages: Input a, b, c
i. Easily understood. Total = a + b + c
ii. Easily maintained.
iii. The codes are changeable. Average = Total / 3
Output a, b, c
 Disadvantages: Output Average
Cannot be executed in the computer. END

c)IPO Chart (Input Process


Output) Problem 1
Chart IPO (input output processing)
Compiling information available in the Detailed get in shape with a display input,
processing and output  Uncle Ahmad wants to buy 5 cans of paint
to paint his house. The price for a can of
paint is RM 25.50. Calculate the price to
be paid for 5 cans of paint to buy.

17
2/17/2011

Problem 2
 analysis of the problem:
1) input:  A lecturer to determine the grade a
Number of cans of paint purchased, the student based on the marks obtained by
price of a can of paint students in the special examination. If you
2) The formula / process: score between 85 and 100, grade A if the
5 cans of paint price = price x number of student is not the student will receive a
cans grade of B. What grades will be earned by
3) output: the student if the score is 89?
prices for purchased 5 cans of paint

Problem:
 1) input:
marks obtained A photostat shops charge 5 cents
2) The formula / process: for each page copied. Design
If you score 85-100, is a grade A solutions to calculate the fee should
If the contrary is a B grade imposed if a number of pages that have
3) Output: been
grade obtained diphotostat.

18
2/17/2011

Example 1:
Problem: To calculate the amount of water bill

 definition and identify problems


plan using the variable
Writing pseudo code
Design a flow chart (design software)

Example 2:
Problem: To calculate area of a circle
Example : Calculate the Salary of
Employee

19
2/17/2011

d)Structure Charts
 Structure chart is an additional method in
preparing programs that has many sub
modules.
 It consists rectangular boxes, which
represents all the sub modules in a
program and is connected by arrows.
 It illustrates the top-down design of a
program and is also known as hierarchical
chart because its components are in
hierarchical form.
 The advantage is that it is easy to be drawn
and to be changed.

20

Вам также может понравиться