Lecture 2: Logical Problems with Choices Sumber dari : user.engineering.uiowa.edu/~xwu3/epsii/Lecture02/lecture2.ppt.

Slides:



Advertisements
Presentasi serupa
Introduction to Algorithm evaluation Soal Matrikulasi Buka Buku
Advertisements

Bab 2 Struktur Dasar.
Algoritma : CONTROL STRUCTURES
Algoritma dan Struktur Data
1 Algoritma Bahasa Pemrograman dan Bab 1.1. Pengertian Algoritma.
Control Structures in Java Risanuri Hidayat, Ir., M.Sc.
KONTROL ALUR EKSEKUSI PROGRAM
Function.
MINGGU 2 Java Programming (MKB614C)
LOGIKA ALGORITMA Pertemuan 6.
Pemrograman Berorientasi Objek Bab 1 – Pemrograman Terstruktur.
Materi-Materi Pengantar Algoritma Konsep Bahasa Pemrograman Flowchart
2. Introduction to Algorithm and Programming
Fungsi Lecture 7. Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into.
STRUCTURAL CONTROL STATEMENT  If  If…..else….  If ….elseif…else.
Chapter 1-a FLOW CHART.
SUBPROGRAM IN PASCAL PROCEDURE Lecture 5 CS1023.
1 Flowchart Techniques Is: A graphical representation of the sequence of operations in an information system program The plan to be followed when the program.
GRADE/ SEMESTER : VII/ I
K-Map Using different rules and properties in Boolean algebra can simplify Boolean equations May involve many of rules / properties during simplification.
TEKNIK PENGINTEGRALAN
Struktur dasar & Perintah dasar
Activity Diagram Shinta P.. For Bussiness Modeling, Activity diagrams describe the activities of a class. It is used for the following purposes: (Bennet.
Pertemuan Operasi Seleksi
BLACK BOX TESTING.
REPETITION CONTROL STRUCTURES
Refresh C++ Bahasa C dibuat pada tahun 1978 untuk Sistem Operasi Unix oleh Bell Labs (Ken Thompson dan Dennis M. Ritchie). –Buku The C Programming Language.
1 Diselesaikan Oleh KOMPUTER Langkah-langkah harus tersusun secara LOGIS dan Efisien agar dapat menyelesaikan tugas dengan benar dan efisien. ALGORITMA.
Dasar Pemrograman Java Pertemuan 2 Pemrograman Berbasis Obyek.
Menulis Kolom  Kolom adalah opini atau artikel. Tidak seperti editorial, kolom memiliki byline.  Kolom Biasanya ditulis reguler. Biasanya mingguan atau.
1 Pertemuan 09 Kebutuhan Sistem Matakuliah: T0234 / Sistem Informasi Geografis Tahun: 2005 Versi: 01/revisi 1.
HAMPIRAN NUMERIK SOLUSI PERSAMAAN NIRLANJAR Pertemuan 3
1 Pertemuan 15 Game Playing Matakuliah: T0264/Intelijensia Semu Tahun: Juli 2006 Versi: 2/1.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
1 Pertemuan 2 Algoritma dan Pemrograman Matakuliah: T0016/Algoritma dan Pemrograman Tahun: 2005 Versi: versi 2.
9.3 Geometric Sequences and Series. Objective To find specified terms and the common ratio in a geometric sequence. To find the partial sum of a geometric.
OPERATOR DAN FUNGSI MATEMATIK. Operator  Assignment operator Assignment operator (operator pengerjaan) menggunakan simbol titik dua diikuti oleh tanda.
Cursor MI2163 Dasar Pemrograman Basis Data. Introduction Cursor merupakan suatu variabel yang digunakan untuk menampung hasil query yang terdiri atas.
PERFORMANCE-BASED ASSESMENT DEFINITION CHARACTERISTIC S DESIGNING PERFORMANCE ASSESSMENT END TERM OF PERFORMANCE ASSESSMENT.
Visual Basic for Aplications in powerpoint. What is Visual Basic for Aplications? Visual Basic for Applications (VBA) is a very powerful objectoriented.
Struktur Kontrol Struktur kontrol if Struktur kontrol if-else
Konsep Pemrograman 3
DIG1G3 Implementasi Struktur Data
IF … THEN …, IF … THEN … ELSE … CASE … OF …
THE GUIDANCE OF PASSING THE TEST
Konsep pemrograman LOOP
Pengujian Hipotesis (I) Pertemuan 11
Pemrograman Terstruktur
BAB 4 Flow Control & Looping
Aliran Kendali (Flow Control)
Dasar-Dasar Pemrograman
Introduction 03 using to Algorithm C / C++ teknik dasar Algoritma.
Bahasa Pemprograman Dasar Pertemuan 4
Pemrograman Berorientasi Objek
Operator Pada C Amaludin Arifia, M.Kom.
Algorithms and Programming Searching
Recursive function.
Bahasa Pemrograman (Pemrograman Visual)
Kk ilo Associative entity.
Bab 2 Struktur Dasar.
STRUKTUR DATA.
Pertemuan 4 CLASS DIAGRAM.
Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 3.
Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 4.
Lesson 2-1 Conditional Statements 1 Lesson 2-1 Conditional Statements.
Fix problems opening Norton  Fix problems opening Norton This problem can happen after you update Norton. To fix the matter, restart the computer. Fix.
If you are an user, then you know how spam affects your account. In this article, we tell you how you can control spam’s in your ZOHO.
INTERROGATIVE ADJECTIVE. DEFINITION FUNCTION EXAMPLE QUESTION.
Draw a picture that shows where the knife, fork, spoon, and napkin are placed in a table setting.
2. Discussion TASK 1. WORK IN PAIRS Ask your partner. Then, in turn your friend asks you A. what kinds of product are there? B. why do people want to.
Transcript presentasi:

Lecture 2: Logical Problems with Choices Sumber dari : user.engineering.uiowa.edu/~xwu3/epsii/Lecture02/lecture2.ppt

Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach for solving it While writing a program Know what “building blocks” are available Using good programming principles

Algorithms Computing problems All can be solved by executing a series of actions in a specific order Algorithms: An algorithm is a clearly specified set of simple instructions to be followed to solve a problem Actions to be executed The order in which these actions are to be executed Program control Specify order in which statements are to be executed

Control Structures Sequential execution Normally, statements are executed one after the other in the order written Transfer of control When the next statement executed is not the next one in sequence Overuse of goto statements led to many problems All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default Selection structures Three types: if, if … else, and switch Repetition structures Three types: while, do … while and for

Pseudocode Artificial, informal language that helps develop algorithms Similar to everyday English Not actually executed on computers Help “think out” a program before writing it Easy to convert into a corresponding C program Consists only executable statement Definitions are not executable statements

Flowchart Graphical representation of an algorithm Drawn using certain special-purpose symbols connected by arrows called flowlines Special-purpose symbols Rectangle (action) symbol: any type of action. Oval symbol: the beginning or end of a program Small circle (connector) symbol: the entry or exit of a portion of an algorithm. Diamond symbol: indicate that a decision is to be made. Single-entry/single-exit Flowcharting C’s sequence stucture

if Selection Statement Selection structure Used to choose among alternative courses of action Example - Pseudocode: if student’s grade is no less than 60 print “Passed” If condition true Print statement executed and program goes on to next statement. If condition false Print statement is ignored and the program goes onto the next statement condition

if Selection Statement Pseudocode statement in C if ( grade >= 60) printf( “Passed\n” ); C code corresponds closely to the pseudocode Flow chart for the if selection statement Diamond symbol (decision symbol) Indicates decision is to be made Contains an expression that can be true or false Test the condition, follow appropriate path condition

if … else Selection Statement if … else Specifies an action to be performed both when the condition is true and when it is false if: Only performs an action if the condition is true. Problem: Pseudocode: Read in 2 numbers and print in non-decreasing order. Read in two numbers, num1 and num2. If num1 is no larger than num2 Print “num1 num2” else Print “num2 num1”

if … else Selection Statement Flowchart begin Read in two numbers: num1 and num2 num1 <= num2 Print “num1 num2” true false end Print “num2 num1” Flowcharting the double- selection if...else statement

if … else Selection Statement C code

Nested if … else Statements Test for multiple cases by placing if…else selection statements inside if…else selection statement Once condition is met, rest of statements skipped Example - Pseudocode If student’s grade is greater than or equal to 90 Print “A” else If student’s grade is greater than or equal to 80 Print “B” else If student’s grade is greater than or equal to 70 Print “C” else If student’s grade is greater than or equal to 60 Print “D” else Print “F”

Nested if … else Statements Flowchart Print “A” true score>=90 false score>=80 Print “B” true false score>=70 Print “C” true false score>=60 Print “D” true Print “F” false

Nested if … else Statements C code /* Convert a student's score to grade */ #include /* function main begins program execution */ int main( void ) { int score; /* score of the student */ printf( "Enter the score\n" ); /* prompt */ scanf( "%d", &score ); /* read an integer */ if ( score >= 90 ) printf( "The grade is 'A'.\n" ); else if ( score >= 80 ) printf( "The grade is 'B'.\n" ); else if ( score >= 70 ) printf( "The grade is 'C'.\n" ); else if ( score >= 60 ) printf( "The grade is 'D'.\n" ); else printf( "The grade is 'F'.\n" ); return 0; /* indicate that program ended successfully */ } /* end function main */

Compound Statement Set of statements within a pair of braces Example: if ( grade >= 60 ) printf( "Passed.\n" ); else { printf( "Failed.\n" ); printf( "You must take this course again.\n" ); } Without the braces, the statement printf( "You must take this course again.\n" ); would be executed automatically. A compound statement can be placed anywhere in a program that a single statement can be placed.

Write a program that completes the following: Read in three integers and determine the largest. You should only use if/else statements for the logic in your code. Submit your maxnum.c file to the dropbox called Maximum Number and complete Program Quiz 2. In-Class Programming Exercise