220 likes | 241 Views
The Need for Program Design. A program must be designed before it is written. You should not go to the keyboard and start typing instructions into the program before designing it. STAIR problem çözme süreci. S tate the problem (Problemi tanımlayın)
E N D
The Need for Program Design • A program must be designed before it is written. You should not go to the keyboard and start typing instructions into the program before designing it.
STAIR problem çözmesüreci • State the problem (Problemi tanımlayın) • Identify the tools available for solving the problem (Problemi çözmek için mevcut araçları belirleyin) • Write an algorithm (Bir algoritma yazın) • Implement the solution (Çözümü gerçekleştirin) • Refine the solution (Çözümü sadeleştirin)
Write the algorithm to make a peanut butter and jelly sandwich 1. Put the bread, peanut butter, jelly, knife, and plate onto the workspace. 2. Place two slices of bread on the plate. 3. Using the knife, spread peanut butter on one slice. 4. If you want jelly, using the knife, spread jelly on the other slice. 5. Slap the two slices together, sticky side in. 6. Repeat steps 2 through 5 for each sandwich needed. 7. Eat the sandwiches.
Bir Algoritmanın Özellikleri • Has input, performs a process, and gives output. • Must be clear and unambiguous (belirsiz). • Must correctly solve the problem. • Can be followed with paper and pencil. • Must execute in a finite number of steps.
Flowchart = Akış Diyagramı • It is said that a picture is worth a thousand words, and the flowchart provides a pictorial representation of program logic. • Flowcharts are made up of industry-standard symbols.
Dikdörtgen: İşlem Baklava: Karar Paralel Kenar: Giriş ya da Çıkış Daire: Bağlantı Ok: Akış yönü Oval: Başlama ya da Durma noktası Akış Diyagramı Sembolleri ve Fonksiyonları
Bir arkadaşınızı telefonla aramak için izlenebilecek bir akış diyagramı
The Rules of Flowcharting • Rule #1— Use standard flowcharting symbols. • Rule #2— The flowchart's logic should generally flow from the top of the page to the bottom of the page, and from left to right. • Rule #3— The decision symbol is the only symbol that can have more than one exit point, and it always has two. • Rule #4— A decision symbol should always ask a yes or no question. • Rule #5— Instructions inside the symbols should be clear English descriptions, not computerese or programming language statements.
Yağlı Ballı Ekmek Akış Diyagramı 1. Put the bread, peanut butter, jelly, knife, and plate onto the workspace. 2. Place two slices of bread on the plate. 3. Using the knife, spread peanut butter on one slice. 4. If you want jelly, using the knife, spread jelly on the other slice. 5. Slap the two slices together, sticky side in. 6. Repeat steps 2 through 5 for each sandwich needed. 7. Eat the sandwiches.
Karmaşık Problemler • Bir evliliği gerçekleştirmek için gerekli algoritmanın yazılması • Bir bordro programına ait algoritmanın yazılması • Bir bankamatiğe ait algoritmanın yazılması
Karmaşık Problemlerin Çözümünde Algoritma Süreci: Problemin Parçalara Ayrıştırılması • To attack more complex problems, top-down design is used. • Intop-down design, the overall problem is broken into the main tasks (usually input, process, output),and then each of these tasks is broken down into subtasks until a simple solution can be seen for eachsubtask.
Hierarchy Charts (Organizasyon Şeması) • Usually hierarchy charts are used as a help in top-down design. Hierarchy charts differ fromflowcharts in that they indicate what should be done, not how the job will be accomplished.
Problemin Parçalara Ayrıştırılması • the process of taking the overall problem and breaking it down more and more until you finalize all the details. • One of the keys to top-down design is that it forces you to put off the details until later. Top-down design forces you to think in terms of the overall problem for as long as possible. Top-down design keeps you focused.
Parçalara Ayırma Süreci • Determine the overall goal. • Break that goal into two, three, four, or more detailed parts. Too many more parts make you leave out things. • Put off the details as long as possible. Repeat step 2 until you cannot reasonably break down the problem any further.
Bir bankamatikteki görevlerin parçalara ayrıştırılması
The algorithm for a simple ATM machine 1. Get the password from the user. 2. If the password is not valid, construct an error message and skip to step 6. 3. Get the inputs. 3.1. Get the transaction type (deposit or withdrawal), and the amount from the user. 3.2. Get the current balance from the bank. 4. If the transaction type is deposit, add the amount to the current balance. 5. If the transaction type is withdrawal, check the current balance. 5.1. If amount is greater than the current balance, construct an error message and skip to step 6. 5.2. If amount is equal to or less than the current balance, subtract the amount from the current balance. 6. Output the error message or the cash, and the current balance. 7. Ask the user whether to repeat steps 3 through 6 for another transaction.