You are on page 1of 42

PROGRAMMING

CONCEPT &
A SURVEY OF
PROGRAMMING
TECHNIQUE
PEMROGRAMAN BERORIENTASI OBJEK
PENDIDIKAN TEKNIK INFORMATIKA KOMPUTER
ALFA FARIDH SUNI
2021
WHY WE DO
PROGRAMMING
• We have problem,
• We need solution(s),
• We need computer’s help to solve
our problem.
• We need to command the computer
• Set of instructions which is run by
computer à Program
SO FAR….
A computer is a device that can perform computations and
make logical decisions billions of times faster than human
beings can.

Computers process data under the control of sets of


instructions called computer programs. These programs
guide the computer through orderly sets of actions specified
by people called computer programmers.
COMPUTER
ORGANIZATION
Every computer may be envisioned as divided into six logical
units
1. Input unit.
2. Output unit.
3. Memory unit.
4. Arithmetic and logic unit (ALU).
5. Central processing unit (CPU).
6. Secondary storage unit.
PROGRAMMING
LANGUAGE
• We speak our language (human
language)
• Computer don’t speak our language
• Computer speak in 0 and 1
(machine/binary language)
• We need lingua franca* /
intermediate language
• We need Programming Language
*(noun) A medium of communication between peoples of different
languages.
Source: The American Heritage® Dictionary of the English Language, 4th
Edition
WHAT WE NEED TO
PROGRAM
• Source code, compiler, Integrated Development
Environment / IDE (optional)
HOW TO SOLVE A PROBLEM

1.Understanding the problem


2.Devising* a plan
3.Carrying out the plan
4.Looking back

• (verb) to form in the mind by new combinations or applications of ideas or principles . Source: Merriam-Webster dictionary
• (verb) plan or invent (a complex procedure, system, or mechanism) by careful thought. Source: translate.google.com
HOW TO PROGRAM
1. Think of solution(s) for your
problem
2. Write the code
3. Compile the code
4. Run the program
5. Debug the program
Source: Problem Solving and Program Design in C 5th Edition by Jeri R. Hanly and Elliot B. Koffman
PROCESS OF WRITING
A C++ PROGRAM
PROCESS OF WRITING
A C++ PROGRAM
Step 1: Write the source codes (.cpp) and header files (.h).
Step 2: Pre-process the source codes according to the preprocessor
directives. Preprocessor directives begin with a hash sign (#), e.g.,
#include and #define. They indicate that certain manipulations (such as
including another file or replacement of symbols) are to be performed
BEFORE compilation.
Step 3: Compile the pre-processed source codes into object codes
(.obj, .o).
Step 4: Link the compiled object codes with other object codes and the
library object codes (.lib, .a) to produce the executable code (.exe).
Step 5: Load the executable code into computer memory.
Step 6: Run the executable code, with the input to produce the desired
output.
HELLO WORLD
/*
* First C++ program that says hello (hello.cpp)
*/
#include <iostream> // Needed to perform IO operations
using namespace std;

int main() { // Program entry point


cout << "hello, world" << endl; // Say Hello
return 0; // Terminate main()
} // End of main
function
COMPILE IT... RUN IT...
• Compile
// Windows (CMD shell) - Build "hello.cpp" into "hello.exe"
> g++ -o hello.exe hello.cpp

// UNIX/Linux/Mac (Bash shell) - Build "hello.cpp" into "hello"


$ g++ -o hello hello.cpp

• Run
// Windows (CMD shell) - Run "hello.exe" (.exe is optional)
> hello
hello, world

// UNIX/Linux/Mac (Bash shell) - Run "hello" (./ denotes the current directory)
$ ./hello
hello, world
JAVA COMPILATION
STEP
PROCESS OF WRITING
A JAVA PROGRAM
Step 1: Install Java JDK
Step 2: Write the source code save as .java file extension
Step 3: Compile the source code
Step 4: if the compilation is successful there will be new file with same
name but with .class file extension, the executable code.
Step 5: Run the executable code (.class file)
HELLO WORLD
/*
* First JAVA program that says hello
(helloWorld.java)
*/

class helloWorld {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java
program.");
}
}
COMPILE IT... RUN IT...
• Compile
// Window, Mac, Unix all the same instruction
> javac helloWorld.java

• Run
// Window, Mac, Unix all the same instruction
> java helloWorld

To compile need Computer with JDK (Java Compiler & JRE )


To run program need Computer with JRE (Java Runtime
Environment)
TODAYS OUTLINE
A Survey of Programming Techniques:
1. Unstructured Programming
2. Procedural Programming
3. Modular Programming
4. Object-Oriented Programming
UNSTRUCTURED
PROGRAMMING
UNSTRUCTURED
PROGRAMMING
• Simple
• Small
• Consist only one main program
• In “main program” consist of :
• Sequence of commands
• Statement which modify data
• Using global variabel (data)
UNSTRUCTURED
PROGRAMMING
Disadvantages:
• Problem arise when our program become large.
• Same statement sequence is needed at different locations
within the program, the sequence must be copied.

Solution
• extract these sequences, name them and offering a
technique to call and return from these procedures.
PROCEDURAL
PROGRAMMING
Procedure & Function
• With procedural programming you are able to combine
returning sequences of statements into one single place.
• A procedure call is used to invoke the procedure.
• After the sequence is processed, flow of control proceeds
right after the position where the call was made
PROCEDURAL
PROGRAMMING
PROCEDURAL
PROGRAMMING
• Parameters
• Procedures of procedures ( sub procedures)
• Programs can now be written more structured and error
free. Why…?
• Program can be viewed as a sequence of procedure calls.
• The main program is responsible to pass data to the
individual calls, the data is processed by the procedures
and, once the program has finished, the resulting data is
presented.
• Thus, the flow of data can be illustrated as a hierarchical
graph, a tree,
PROCEDURAL
PROGRAMMING
PROCEDURAL
PROGRAMMING
Summary:
• Single program which is divided into small pieces called
procedures.
• General procedures or groups of procedures also in other
programs, they must be separately available.
• modular programming allows grouping of procedures into
modules.
MODULAR
PROGRAMMING
• Procedures of a common functionality are grouped
together into separate modules.
• A program is now divided into several smaller parts which
interact through procedure calls and which form the whole
program
MODULAR
PROGRAMMING
MODULAR
PROGRAMMING
• Each module can have its own data.
• This allows each module to manage an internal state
which is modified by calls to procedures of this module.
• However, there is only one state per module and each
module exists at most once in the whole program.
• Module divided into:
• the interface definition file
• the implementation file
MODULAR
PROGRAMMING
• Interface definitions just describe what is available and
not how it is made available.
• You hide the information of the implementation in the
implementation file.
• This is a fundamental principle in software engineering:
Information Hiding
• This enables you to change the implementation
• The calls to provided procedures remain the same.
MODULAR
PROGRAMMING
Disadvantages:
• Explicit Creation and Destruction
• Decoupled Data and Operations
• Missing Type Safety
• Strategies and Representation

Solutions:
• In object-orientation, structure is organized by the data.
• Programs get structured by the data rather than operations.
• Data specifies valid operations.
• Modules group data representations together.
OBJECT-ORIENTED
PROGRAMMING
• Program consist of : a web of interacting objects,
each house-keeping its own state
• object-oriented programming we would have as
many objects as needed.
• Each object is responsible to initialize and destroy
itself correctly. Consequently, there is no longer
the need to explicitly call a creation or termination
procedure.
• Some authors describe object-oriented
programming as programming abstract data
types and their relationships.
OBJECT-ORIENTED
PROGRAMMING
ABSTRACTION
• Handling Problems:
• The first thing with which one is confronted when writing
programs is the problem
• Typically you are confronted with ``real-life'' problems and
you want to make life easier by providing a program for the
problem
• However, real-life problems are nebulous and the first
thing you have to do is to try to understand the problem to
separate necessary from unnecessary details: You try to
obtain your own abstract view, or model, of the problem.
This process of modeling is called abstraction.
ABSTRACTION
ABSTRACTION
• The model defines an abstract view to the problem. This
implies that the model focuses only on problem related
stuff and that you try to define properties of the problem.
• Properties of the Problem:
• the data which are affected and
• the operations which are identified
• Abstraction is the structuring of a nebulous problem into
well-defined entities by defining their data and operations.
• These entities combine data and operations. They are not
decoupled from each other.
ABSTRACT DATA
TYPES
ABSTRACT DATA
TYPES
Definition (Abstract Data Type), An abstract data type (ADT) is
characterized by the following properties:
1. It exports a type.
2. It exports a set of operations. This set is called interface.
3. Operations of the interface are the one and only access
mechanism to the type's data structure.
ABSTRACT DATA TYPES
& OBJECT-ORIENTATION
• ADTs allows the creation of instances with well-defined
properties and behavior.
• In object-orientation ADTs are referred to as classes.
Therefore a class defines properties of objects which are
the instances in an object-oriented environment.
• ADTs define functionality by putting main emphasis on the
involved data, their structure, operations as well as
axioms and preconditions.
• Consequently, object-oriented programming is
``programming with ADTs'': combining functionality of
different ADTs to solve a problem.
• Therefore instances (objects) of ADTs (classes) are
dynamically created, destroyed and used.
NEXT…..
Object-oriented programming in detail.
SEKIAN
TERIMA KASIH

You might also like