latihan pemrograman dasar

16
LATIHAN PEMROGRAMAN DASAR Modularitas – Menggunakan Parameter – Membuat Program Faktorial & Deret Fibonacci

Upload: dwiki-darmawan

Post on 02-Sep-2015

228 views

Category:

Documents


9 download

DESCRIPTION

nv hfjc kb khcjgcjb gckkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkh

TRANSCRIPT

  • LATIHAN PEMROGRAMAN DASARModularitas Menggunakan Parameter Membuat Program Faktorial & Deret Fibonacci

  • Kuis (Product Orders Report) contdThe 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) contdThe 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) contdACME SPAREPART ORDERS REPORTEach 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.

    PRODUCT NO.PRODUCT DESCRIPTIONUNITS ORDEREDTOTAL AMOUNT DUEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Jawaban Kuis IPO Diagram

    InputProcessOutputFile:Product_noProduct_descUnits_orderedRetail_priceFreight_chargesPackaging_costRead fileGet input from fileCalculate Total_amount_dueCheck Total_amount_due for discountCalculate Final_amountPrint Final_amountProduct_noProduct_descUnits_orderedFinal_amount

  • Jawaban Kuis Hierarchy Chart

  • Jawaban Kuis - PseudocodeProducts_Order_ReportsBEGINRead product_no, product_desc, units_ordered, retail_price, freight_charges, packaging_costCalculate_total_amount(units_ordered,retail_price, freight_charges, packaging_cost)Print_result(product_no, product_desc, units_ordered, final_amount)END

  • Jawaban Kuis - PseudocodeCalculate_total_amount(units_ordered, retail_price, freight_charges, packaging_cost)Total_amount_due = units_ordered * retail_priceCheck_discount(total_amount_due)total_amount_due = total_amount_due discounttotal_freight = (freight_charges+packaging_cost)* units_orderedFinal_amount = total_amount_due + total_freightReturn Final_amountEND

  • Jawaban Kuis - PseudocodeCheck_discount(total_amount_due)IF total_amount_due > 100Discount = total_amount_due x 0,1ELSEDiscount = 0ENDIF

  • Jawaban Kuis PseudocodePrint_result(product_no, product_desc, units_ordered, final_amount)Print headingDOWHILE line =< 45DOWHILE more recordsPrint product_noPrint product_descPrint units_orderedPrint final_amountline++ENDDOPage++ENDDO

  • Program FaktorialKonsep FaktorialMisal dipilih n = 5, maka n! = 5x4x3x2x1Menggunakan decrementPseudocodeDimodularisasikan

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

  • Fungsi Program Faktorialint i;int hasil_akhir = 1;

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

  • Program Implementasi Deret FibonacciKonsep deret Fibonacci:0 1 1 2 3 5 8 13 21 ... etcAngka berikut adalah jumlah dari 2 angka pendahulunyaAlgoritma:Angka pertama = a, angka kedua = b, jumlah deret yang diinginkan = nSet a = 0, b = 1Print a , bDOWHILE i
  • Fungsi Program Fibonacciint a,b,c;int i,n;a = 0;b = 1;printf (\t%d\t%d, a,b);for (i =0; i
  • LatihanBuat 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:

    - Membahas UTS & Kuis**dalam modularitas, variabel yang ada HARUS dideklarasikan dulu sebagai parameter*mengembalikan nilai**