The Need for Program Design A program must be designed before it is written. You should not go to...

21
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.

Transcript of The Need for Program Design A program must be designed before it is written. You should not go to...

Page 1: 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.

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.

Page 2: 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.

STAIR problem çözme sü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)

Page 3: 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.

Algoritma = Pseudocode

Page 4: 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.

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.

Page 5: 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.

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.

Page 6: 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.
Page 7: 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.

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.

Page 8: 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.

Akış Diyagramı Sembolleri ve Fonksiyonları

• 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ı

Page 9: 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.

• Bir arkadaşınızı telefonla aramak için izlenebilecek bir akış diyagramı

Page 10: 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.

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.

Page 11: 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.

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.

Page 12: 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.

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ı

Page 13: 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.

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.

• In top-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 each subtask.

Page 14: 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.

Hierarchy Charts (Organizasyon Şeması)

• Usually hierarchy charts are used as a help in top-down design. Hierarchy charts differ from flowcharts in that they indicate what should be done, not how the job will be accomplished.

Page 15: 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.

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.

Page 16: 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.

Parçalara Ayırma Süreci

1. Determine the overall goal.

2. Break that goal into two, three, four, or more detailed parts. Too many more parts make you leave out things.

3. Put off the details as long as possible. Repeat step 2 until you cannot reasonably break down the problem any further.

Page 17: 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.

Bir Evlilik Töreninin Parçalara Ayrıştırılması

Page 18: 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.

Bir Bordro Programının Parçalara Ayrıştırılması

Page 19: 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.

Bir bankamatikteki görevlerin parçalara ayrıştırılması

Page 20: 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.

The flowchart for a simple ATM machine

Page 21: 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.

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.