You are on page 1of 16

LATIHAN PEMROGRAMAN

DASAR
Modularitas Menggunakan
Parameter Membuat
Program Faktorial & Deret
Fibonacci

Kuis (Product Orders Report)


contd
The ACME spareparts company wants to
produce a product orders report from its
product orders file. Each record on the file
contains the product number of the item
ordered, the product description, the number
of units ordered, the retail price per unit, the
freight charges per unit, and the packaging
costs per unit. Your algorithm is to read the
product orders file, calculate the total amount
due for each product ordered and print these
details on the product orders report.

Kuis (Product Orders Report)


contd
The amount due for each product is calculated
as the product of the number of units ordered
and the retail price of the unit. A discount of
10% is allowed on the amount due for all orders
over $100. The freight charges and packaging
costs per unit must be added to this resulting
value to determine the total amount due.
The output report is to contain headings and
column heading as specified in the following
chart:

Kuis (Product Orders Report)


contd
ACME SPAREPART ORDERS REPORT
PRODUCT NO.
XXXX
XXXX

PRODUCT
DESCRIPTION
XXXXXXXX
XXXXXXXX

UNITS
ORDERED
XXX
XXX

TOTAL
AMOUNT DUE
XXXX
XXXX

Each detail line is to contain the


product number, product desc.,
number of units ordered, and total
amount due per the order. There is to
be an allowance of 45 detail lines per
page.

Jawaban Kuis IPO Diagram


Input

Process

Output

File:
Product_no
Product_desc
Units_ordered
Retail_price
Freight_charge
s
Packaging_cost

Read file
Get input from file
Calculate Total_amount_due
Check Total_amount_due for
discount
Calculate Final_amount
Print Final_amount

Product_no
Product_desc
Units_ordered
Final_amount

Jawaban Kuis Hierarchy


Chart

Jawaban Kuis - Pseudocode


Products_Order_Reports
BEGIN
Read product_no, product_desc,
units_ordered, retail_price, freight_charges,
packaging_cost
Calculate_total_amount(units_ordered,retail
_price, freight_charges, packaging_cost)
Print_result(product_no, product_desc,
units_ordered, final_amount)
END

Jawaban Kuis - Pseudocode


Calculate_total_amount(units_ordered,
retail_price, freight_charges, packaging_cost)
Total_amount_due = units_ordered * retail_price
Check_discount(total_amount_due)
total_amount_due = total_amount_due discount
total_freight =
(freight_charges+packaging_cost)* units_ordered
Final_amount = total_amount_due + total_freight
Return Final_amount
END

Jawaban Kuis - Pseudocode


Check_discount(total_amount_due)
IF total_amount_due > 100
Discount = total_amount_due x 0,1
ELSE
Discount = 0
ENDIF

Jawaban Kuis Pseudocode


Print_result(product_no, product_desc, units_ordered,
final_amount)
Print heading
DOWHILE line =< 45
DOWHILE more records
Print product_no
Print product_desc
Print units_ordered
Print final_amount
line++
ENDDO
Page++
ENDDO

Program Faktorial
Konsep Faktorial
Misal dipilih n = 5, maka n! =
5x4x3x2x1
Menggunakan decrement
Pseudocode
Dimodularisasikan

Konsep Algoritma dari


Faktorial
Pengguna memasukkan nilai yang akan
difaktorialkan (input)
Hasil akhir berupa hasil faktorial (output)
Algoritma:
Iterasi dimulai dari n sampai 0 (decrement)
DOWHILE nilai n =1
Nilai akhir dikalikan dengan nilai akhir 1
Decrement n
ENDDO

Fungsi Program Faktorial


int i;
int hasil_akhir = 1;
for(i = n; i > 0; i = i 1)
{
hasil_akhir = hasil_akhir * i;
}

Program Implementasi Deret


Fibonacci
Konsep deret Fibonacci:
0 1 1 2 3 5 8 13 21 ... etc
Angka berikut adalah jumlah dari 2 angka pendahulunya
Algoritma:
Angka pertama = a, angka kedua = b, jumlah deret yang
diinginkan = n
Set a = 0, b = 1
Print a , b
DOWHILE i <= n
c = a+b
a=b
b=c
Print c
ENDDO

Fungsi Program Fibonacci


int a,b,c;
int i,n;
a = 0;
b = 1;
printf (\t%d\t%d, a,b);
for (i =0; i<=n;i++)
{
c=a+b;
a = b;
b = c;
printf(\t%d, c);
}
return(0);

Latihan
Buat modularisasi dari program
Fibonacci dan Faktorial di atas!
Latihan modularisasi lebih lanjut:
Diberikan a,b,c sebagai sisi-sisi dari
sebuah segitiga. Hitung nilai A, apabila
diberikan rumus A sebagai berikut.
Di mana nilai s adalah:

You might also like