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.

Similar presentations

Presentation on theme: "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."— Presentation transcript:

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 before designing it.

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

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

6

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

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

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

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

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

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

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

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

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

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

20
The flowchart for a simple ATM machine

21
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 Get the inputs Get the transaction type (deposit or withdrawal), and the amount from the user 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 If amount is greater than the current balance, construct an error message and skip to step 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.