TM-01: The Essence of Programming & Problem Solving TMB208 – Pemrograman Teknik Kredit: 3 (2-3) PROBLEM SOLVING • Engineers must analyze and solve a wide range of technical problems. • Some will be reasonably simple singlesolution problems. • Others will be open-ended and will likely require a team of engineers from several disciplines. Some problems may have no clear solution. PROBLEM SOLVING PROBLEM SOLVING INVOLVES: •EXPERIENCE •KNOWLEDGE •PROCESS •ART FOCUS: Computer Assisted Problem Solving Computers are good tools for solving rulebased problems using decision rules PROBLEM SOLVING SOME SAY ENGINEERING PROBLEM SOLVING REQUIRES A COMBINATION OF SCIENCE AND ART: SCIENCE ART • Math • Judgment • Physics • Experience • Chemistry • Common-Sense • Mechanics • Know-How • Etc. • Etc. STEPS IN PROBLEM SOLVING • IDENTIFY THE PROBLEM – YOU CAN’T FIX IT IF YOU DON’T KNOW WHAT IS BROKEN. • DETERMINE WHAT IS REQUIRED FOR THE SOLUTION – WHAT IS KNOWN? – WHAT IS UNKNOWN? – ANY RESTRICTIONS OR LIMITATIONS? – ANY SPECIAL CASES? STEPS IN PROBLEM SOLVING (CONT’D) • DEVELOP A STEP-BY-STEP PLAN (ALGORITHM). – HOW ARE YOU GOING TO FIX IT? • OUTLINE THE SOLUTION IN A LOGIC DIAGRAM • EXECUTE THE PLAN. – KEEP TRACK OF WHAT WORKS AND WHAT DOESN’T. PROBLEM SOLVING EXAMPLE Problem: Fill a bottle with stones Instructions: • Document any assumptions that may be required • Write a step-by-step procedure for solving the problem • Do this in pairs first then have a solution for your table PROBLEM SOLVING EXAMPLE Assumptions: • Bottle is present • Stones are present • There are enough stones to fill bottle • Bottle is empty (or at least not full) • Some (or all) stones fit through opening PROBLEM SOLVING EXAMPLE Algorithm: 1. Set bottle upright near stones 2. Check to see if bottle is full. If so, then go to Step #6 3. Pick up a stone and try to put it in bottle 4. If stone too large to fit, discard stone, and go to Step #3 5. Otherwise, the stone fits, go to Step #2 6. Stop PROBLEM SOLVING EXAMPLE Problem: Solving quadratic equation in the form of AX2+BX+C=0, where A, B,C are constants. Instructions: • Document any assumptions that may be required • Write a step-by-step procedure for solving the problem • Do this in pairs first then have a solution for your table PROBLEM SOLVING EXAMPLE Assumptions (Versi 1): • A ≠ 0, krn persamaan kuadrat • Solusi dari persamaan tersebut adalah bilangan riil PROBLEM SOLVING EXAMPLE Algorithm (versi 1): 1. Read the values of A, B & C 2. Compute D = B2 – 4AC . 3. Compute X1 = (-B + √D) / (2A) 4. Compute X2 = (-B - √D) / (2A) 5. Stop PROBLEM SOLVING EXAMPLE Assumptions (Versi 2): • None (no assumptions) PROBLEM SOLVING EXAMPLE Algorithm (versi 2): 1. Read the values of A, B & C 2. If A = 0 then go to Step #7 3. Compute D = B2 – 4AC . 4. If D < 0 then go to Step #7 5. Compute X1 = (-B + √D) / (2A) 6. Compute X2 = (-B - √D) / (2A) 7. Stop REQUIREMENT ANALYSIS FUNCTIONAL REQUIREMENTS • Based on the functions that must performed by the program. • Question: “What tasks the system must be able to performed?” NON-FUNCTIONAL REQUIREMENTS • Based on program performance: accuracy, speed, reliability, ease of use, reliability • Generally independent o the functional requirements • Question: “How good the system can perform the required functions?” EXAMPLE OF REQUIREMENT ANALYSIS: A case of problem of filling bottle with stones Functional requirements • Fill a bottle with stones Non-functional requirements • Fill a bottle with stones as fast possible • Sucessfully filling stones into the the bottle without breaking up the bottle EXAMPLE OF REQUIREMENT ANALYSIS: A case of solving a quadratic equation Functional requirements • Finding the value(s) of X that satisfies the equation AX2+BX+C=0 Non-Functional requirements • How fast the program can do the function? • How reliable the program can perform the functions? • How friendly the program can perform the functions? EXAMPLE OF REQUIREMENT ANALYSIS: ATM Banking Program Functional requirements • Manjamin validitas kartu ATM • Menjamin validitas nasabah • Memberikan layanan: a. Melihat saldo b. Mengambil uang tunai c. Transfer uang d. Membayar telepon & listrik e. Mencatat semua transaksi Non-Functional requirements • Seberapa cepat sistem ATM dapat melayani fungsinya? • Seberapa mudah (friendly) sistem ATM dapat digunakan? • Seberapa jauh keamanan yang dapat diberikan? • Seberapa handal (reliable) sistem ATM menjalankan fungsinya? Understanding the Mainline Logical Flow Through a Program (continued) Programming Logic and Design, Introductory, Fourth Edition 19 Understanding the Mainline Logical Flow Through a Program (continued) • Modularization of the program: – Keeps the job manageable – Allows multiple programmers to work simultaneously – Keeps the program structured Programming Logic and Design, Introductory, Fourth Edition 20 Housekeeping Tasks • Housekeeping tasks: include all steps that occur at the beginning of the program – Declare variables – Open files – Perform one-time-only tasks such as printing headings – Read the first input record Programming Logic and Design, Introductory, Fourth Edition 21 Declaring Variables • • • • • Assign identifiers to memory locations Specify the name and data type Use meaningful names and follow standards Prefixes may be used to group related variables Declare a variable for each field in a data file Programming Logic and Design, Introductory, Fourth Edition 22 What is “Algorithm”? • A formula or set of steps for solving a particular problem. • It can be expressed in natural languages (e.g. English, Indonesia, Japanese, ...) or in programming languages (Visual Basic, FORTRAN, PHP, Pascal, PHP, C++) • It has a set of inputs that must be transformed into a set of ouputs.