Presentation is loading. Please wait.

Presentation is loading. Please wait.

Från verkligt problem till Datorprogram?

Similar presentations


Presentation on theme: "Från verkligt problem till Datorprogram?"— Presentation transcript:

1 Från verkligt problem till Datorprogram?
Du vet vad Du vill göra, men hur kommer man till ett färdigt C-program?

2 Structure diagram By 2IT Data students … Division Time
F01a-jsp Structure diagram By 2IT Data students … Division ”Morningwhile has gold in mouthd” Morning routine Get dressed Eat breakfast Go to school A strucure diagram is used to divide a problem or activity into smaller parts. These smaller parts can be divided into even smaller parts, and so on. Time KTH / 2IT / Data / Anders Sjögren

3 Sequence (order in time)
F01a-jsp Sequence (order in time) Morning routine Sequence Get dressed Eat breakfast Go to school Sequence parts A sequence describes an activity that can be divided into separate activities, all taking part in a certain order in time. First… Then… And at last… Ex: ”Morning routine” is a sequence of three separate activities, sequence parts. The three activities take place from left to right. First you get dressed, then you eat breakfast and at last you go to school. 8:00 am 8:02 am 8:05 am Time KTH / 2IT / Data / Anders Sjögren

4 Structure diagram Division Time ”Morningwhile has gold in mouthd”
F01a-jsp Structure diagram ”Morningwhile has gold in mouthd” Morning routine Get dressed Eat breakfast Go to school Find clothes Put clothes on Take from wash basket Ask girlfriend where clothes are At the top you see the activity at its whole. At the bottom you see the same activity in many smaller activities. Division Time KTH / 2IT / Data / Anders Sjögren

5 Selection What colour on your socks? Blue Pink White Selection
F01a-jsp Selection What colour on your socks? Selection Blue Pink White If blue exists If blue doesn’t exist, but pink does Else A selection describes a choice between two or more alternatives. Example: When you choose the colour of your socks, you can choose between three different colours. The structure diagram then looks like above. The selection ”What colour on your socks?” consists of three selection parts: ”Blue”, ”Pink” and ”White”. Selection parts are marked with a ring (O, from the word ”Or”) in the top right corner. The selection part always comes with a condition. If the condition is fulfilled, the selection part is chosen. Selection parts KTH / 2IT / Data / Anders Sjögren

6 Structure diagram Division Time ”Morningwhile has gold in mouthd”
F01a-jsp Structure diagram ”Morningwhile has gold in mouthd” Morning routine Take from wash basket Ask girlfriend where clothes are Find clothes Put clothes on Get dressed Eat breakfast Go to school Many glasses of beer One glass of beer When you’ve got dressed, it’s time to eat breakfast. Of course, our breakfast in this case consists of ”Many glasses of beer”. In a structure diagram, ”Many glasses of beer” is equal to ”One beer”, performed many times. Division Time KTH / 2IT / Data / Anders Sjögren

7 Iteration (repetition)
F01a-jsp Iteration (repetition) Drink beer (lightbeer) Many glasses of beer Iteration One beer As long as you’re thirsty An iteration is a repetition of an event. The iteration ”Many glasses of beer” consists of the iteration part ”One beer”. The iteration part always comes with a condition. As long as the condition is fulfilled, the iteration repeats. The iteration part is marked with an asterisk (*, the computers multiply sign) in the top right corner of the square. Iteration part KTH / 2IT / Data / Anders Sjögren

8 Structure diagram Division Time ”Morningwhile has gold in mouthd”
F01a-jsp Structure diagram ”Morningwhile has gold in mouthd” Morning routine Take from wash basket Ask girlfriend where clothes are Find clothes Put clothes on Get dressed Eat breakfast Go to school Many glasses of beer One glass of beer Take a cab Run One step Note that, in this structure diagram, you need to ”Get dressed” before you ”Eat breakfast” and do both before you ”Go to school”. Division Time KTH / 2IT / Data / Anders Sjögren

9 F01a-jsp Flow chart Move foot one step Run Go to school Eat one pancake Eat breakfast Put on the clothes Ask girl/boyfriend Get from laundry basket Search clothes Get dressed Morning route IF you find basket WHILE pancakes <> 0 Take a cab IF money = 0 ELSE WHILE distance to school <> 0 Flowcharts are onedimensional. They are used when you have to describe exactly how the code is processed. The Structure diagram is easier to follow. KTH / 2IT / Data / Anders Sjögren

10 Crossing A B Imagine driving in car B, just behind another car A.
F01a-jsp Crossing Imagine driving in car B, just behind another car A. You come to a crossing. How will you know which direction it will chose? Two cars positioned in a crossing. The car named ”A” has to choose in which direction it want´s to go. How will the car named ”B” know what the car in front of it will do. Let´s make a structure of the problem. A Car A has to make a selection B KTH / 2IT / Data / Anders Sjögren

11 Crossing a selection of directions
F01a-jsp Crossing a selection of directions How can you see in which direction the car in front of you will choose? Selection Crossing Green signal STOP DRIVE Red signal Left blinker Right blinker No blinker Drive left Straight ahead Drive right The car named ”A” have several choies. The choices is depending on what the crossing allows. If the light turns red (condition =”Red signal”) the car must stop. If the light turns green (condition = ”Green signal”) and car ”A” chooses to turn right it will use right blinker (condition = ”Right blinker”). The following car will know by the condition, that car in front of it will turn right. KTH / 2IT / Data / Anders Sjögren

12 not JSP Marriage - a selection? Young man´s future choice Marry girl
F01a-jsp Marriage - a selection? Young man´s future choice Marry girl In what way can you not construct a selection in a srutucturediagram? A selection must have two selectionparts, choices, or else it´s not a selection. The picture above has only one choice to made. This is not correct. not JSP KTH / 2IT / Data / Anders Sjögren

13 Like this! Selectionparts Marry girl Young man´s future choice
F01a-jsp Selectionparts A selection must contain at least two selection components. If It only contains one there is no selection. Young man´s future choice Marry girl Be free!! Like this! We see that the same structurediagram now has two selectionparts. It has become a selection. A choice can be made. This is correct. KTH / 2IT / Data / Anders Sjögren

14 Al Bundy? Young man´s future choice Marry girl
F01a-jsp Al Bundy? It is however possible to leave a selection component empty. We know the end…? Peg.. - make dinner! Marry girl Young man´s future choice This is another example of how you can construct a selection. There is a choice, but nothing happens in one of the selectionparts. KTH / 2IT / Data / Anders Sjögren

15 not JSP Rules of Christmas Santa Claus X-mas day Checks his slade
F01a-jsp Rules of Christmas Santa Claus X-mas day Checks his slade Gives one gift * While gifts not 0 How can you not construct an iteration? This example has an iterationpart placed in a sequence. This is not correct. not JSP KTH / 2IT / Data / Anders Sjögren

16 This is CORRECT!! Santa changed his mind Santa Claus X-mas day
F01a-jsp Santa changed his mind Parts connected to the same component must be of similar type Santa Claus X-mas day Checks his slade First Hands out gifts Last This is CORRECT!! Gives one gift While gifts not 0 * The picture has been changed. We placed a sequencecomponent just above the iterationpart. ”Hands out gifts” is an iteration and ”Gives one gift” is the iterating part. This is correct. KTH / 2IT / Data / Anders Sjögren

17 Paint house - an iteration
F01a-jsp Paint house - an iteration Paint House Get paint * While painter not satisfied with color Paint with Brush * While entire house not painted This is another way you can not construct an iteration. An iteration must only have one iterating part. not JSP KTH / 2IT / Data / Anders Sjögren

18 Now you can begin to paint
F01a-jsp Now you can begin to paint An iteration can only contain one repeated component Paint House Iterations Iteration components OK ! Get paint Begin to paint Get one can of paint Paint with Brush * While painter not satisfied with color While entire house not painted Now we see the correct way to describe the example. KTH / 2IT / Data / Anders Sjögren

19 JSP-editor Henrik Engström JSP-editor
F01a-jsp JSP-editor Henrik Engström JSP-editor applet. Henrik Engström JSP-editor KTH / 2IT / Data / Anders Sjögren

20 F01a-jsp Generate C Generate C-code templates to show the the structure of your programs! KTH / 2IT / Data / Anders Sjögren

21 F01a-jsp Web-Quiz Now there are some ”web-questions” you should answer about structure diagrams! KTH / 2IT / Data / Anders Sjögren

22 Web-Quiz Go on by yourselves! F01a-jsp 2019-05-23
KTH / 2IT / Data / Anders Sjögren

23 Pseudocode Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of a programming language, but is intended for human reading rather than machine reading.

24 BubleSort algorithm in psdeudocode
Example of pseudocode … while not at end of list compare adjacent elements if second is greater than first switch them get next two elements if elements were switched repeat for entire list

25 Lycka till med övningarna!


Download ppt "Från verkligt problem till Datorprogram?"

Similar presentations


Ads by Google