0% found this document useful (0 votes)
40 views

Notation of Algorithm and C++ Programming Language

The document provides an overview of algorithm notation in pseudocode and C++. It discusses the typical structure of algorithms including headers, declarations, and descriptions. It also compares common statements and control structures between pseudocode and C++, such as input/output, selection, and looping. Examples are given of full pseudocode and C++ algorithms to calculate the area of a circle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Notation of Algorithm and C++ Programming Language

The document provides an overview of algorithm notation in pseudocode and C++. It discusses the typical structure of algorithms including headers, declarations, and descriptions. It also compares common statements and control structures between pseudocode and C++, such as input/output, selection, and looping. Examples are given of full pseudocode and C++ algorithms to calculate the area of a circle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

NOTATION of ALGORITHM

and C++ PROGRAMMING


LANGUAGE

Algorithm and Programming

Mangaras Yanu Florestiyanto


Algorithm consist of 3 parts as
follows:

1. Header
2. Dictionary/Declaration
3. Algorithm/Description
Format Syntax Algoritma
HEADER Name/Tittile of Algorithm

DECLARATION/ Type type_name: type [subrange]


DICTIONARY Type type_name : array [min..maks] of type
{Local / Global} Var_name : type
Var_name : array [ min..maks] of type
Const name = value
Procedure Proc_name
(Input/Output[list_of_parameters : type])

BODY of The Assigment notation


ALGORITHM/ Selection/Branching notation
DESCRIPTION Looping/Iteration notation
Call notation

DESCRIPTION A collection of algorithms for each


of The Procedure or Function that is called from
ALGORITMA the Algorithm Body
Wilis-K

“Hello world” Algorithm (in Bahasa):

Algoritma Hello_world
{ program untuk mencetak “Hello world”}

DEKLARASI
{tidak ada}

DESKRIPSI
Write(“Hello world”)

Algoritma dan Pemrograman I


Algorithm to count square
area:
PROGRAM LuasSegi4
CountSquareArea
Algoritma LuasSegi4
{program untuk
{program
{algorithmuntuk menghitung
to count area of aluas
menghitung luas segiempat
square
segiempat dengan
using its
dengan
length
diketahui
dan width} panjang
diketahui panjang dan
dan lebarnya}
lebarnya}
DEKLARASI
DEKLARASI
DICTIONARY
Luas,panjang,lebar
Luas,panjang,lebar
Area, Length, Width :integer
:integer
: integer
ALGORITMA
DESKRIPSI
ALGORITHM
panjang 
panjang
Lenght 10
 10
10
lebar 
lebar
Width 555
Luas 
Luas
Area panjang
Length *** lebar
panjang Width
lebar
write(Luas)
write(Luas)
write(Area)
Pseudo code vs C++

Pseudo code C++

1 #include <unit_name>

2 CONST const_name = value #define const_name value

3 TYPE type_name : data_type typedef data_type type_name;

4 var_name : data_type data_type var_name;


var_name : type_name type_name var_name;

Ex. 1 #include <iostream.h>


2 CONST phi = 3.14 #define phi 3.14
3 TYPE jumlah : integer typedef int jumlah;
4 n : integer int n;
n : jumlah jumlah n;
Statements in Body of Algorithm
Pseudo code C++
1 namavaribel  harga namavar = harga;

2 INPUT(list_of_variables) cin >> var; scanf();


cin.get(); gets();
or cin.getline();
read (list_of_variables)

3 OUTPUT(list_of_variables) cout << var; printf();


or cout << konstanta; puts();
write(list_of_variables)
4 IF <terms> THEN if (terms) action;
action or
ENDIF if (terms)
{ action;
Selection Notation
Pseudo code C++
5 IF <terms> THEN If (terms)
action1 action1;
ELSE else
action2 action2;
ENDIF
or

If (terms)
{ action1;
}
else
{ action2;
}
Selection Notation Cont.
Pseudo code C++
6 DEPEND ON <expression> Switch (expression)
<expression 1> : action_1 {
<expression 2> : action_2 case val_1:
………….. : …………… action_1;
<expression n> : action_n break;
or case val_2:
CASE var_name OF action_2;
expconstan 1 : action_1 break;
expconstan 2 : action_2 ……….. : ……….
………………. : …………… case val_n:
expconstan n : action_n action_n;
ELSE other_action break;
ENDCASE default: other_action;
}
Looping Notation
Pseudo code C++
7 [initialisation] [initialisation]
WHILE <terms> DO while (terms)
list_of_action {
{there is an action so that list_of_action;
meet with stop_terms} /*there is an action so that
ENDWHILE meet with stop_terms*/
}
8 [initialisation] [initialisation]
REPEAT do
list_of_action {
{there is an action so that list_of_action;
meet with stop_terms } /*there is an action so that
UNTIL <stop_terms> meet with stop_terms*/
}
while (loop_terms);
Looping Notation Cont.
Pseudo code
9 Var_name TRAVERSAL [start..end]
list_of_action
or
FOR var  start TO/DOWNTO end STEP counter DO
list_of_action
ENDFOR

C++
for(start; terms; step)
{
list_of_action;
}
Ex. of Pseudo code
Circle_Area
{calculate the circle area by known radius}

DECLARATION
CONST phi = 3.14
r : integer
Area : real

DESCRIPTION
r5
Area  phi * r * r
output(”Radius = ”,r);
output(”Circle area = ”, Area);
Ex. of C++
#include <iostream.h>
#define phi 3.14

main ()
{
int r;
float Area;
r = 5;

Area = phi * r * r;

cout << ”Radius : ” << r;


cout << ”\nCircle Area : ” << Area;
}
Ex. of C++
#include <stdio.h>
#define phi 3.14

main ()
{
int r;
float Area;
r = 5;

Area = phi * r * r;

printf(”Radius : %d”,r);
printf(”\nCircle Area : %f”, Area);
}
QUIZ 1

• Create a Pseudo code and a flowchart to swap 3 values from


variables below:
at first : A = 10, B = 5 dan C = 2
swap to : A = 5, B = 2 dan C = 10
QUIZ 2

• Create a Pseudo code and a flowchart to find the greatest value from
2 variables. Term : the value of each variable must be typed or manual
input and not initialised in program code.

You might also like