Från verkligt problem till Datorprogram? Du vet vad Du vill göra, men hur kommer man till ett färdigt C-program?
Morning routine Structure diagram ”Morningwhile has gold in mouthd” Get dressed Eat breakfastGo to school Time Division By 2IT Data students …
Sequence (order in time) Get dressed Eat breakfastGo to school Morning routine 8:00 am8:02 am8:05 am Time Sequence Sequence parts
Structure diagram ”Morningwhile has gold in mouthd” Find clothesPut clothes on Morning routine Get dressedEat breakfastGo to school Division Time Take from wash basket Ask girlfriend where clothes are
Selection BluePinkWhite What colour on your socks? If blue exists If blue doesn’t exist, but pink does Else Selection Selection parts
Structure diagram ”Morningwhile has gold in mouthd” Many glasses of beer One glass of beer Division Time Morning routine Take from wash basket Ask girlfriend where clothes are Find clothesPut clothes on Get dressedEat breakfastGo to school
Iteration (repetition) Many glasses of beer One beer Drink beer (lightbeer) As long as you’re thirsty Iteration Iteration part
Structure diagram ”Morningwhile has gold in mouthd” Division Time Take a cabRun One step Morning routine Take from wash basket Ask girlfriend where clothes are Find clothesPut clothes on Get dressedEat breakfastGo to school Many glasses of beer One glass of beer
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.
Crossing A B Imagine driving in car B, just behind another car A. You come to a crossing. How will you know which direction it will chose? Car A has to make a selection
Crossing a selection of directions How can you see in which direction the car in front of you will choose? Crossing Green signal STOPDRIVE Red signal Left blinkerRight blinkerNo blinker Drive leftStraight aheadDrive right Selection
Marriage - a selection? Marry girl Young man´s future choice not JSP
Selectionparts Young man´s future choice A selection must contain at least two selection components. If It only contains one there is no selection. Marry girl Be free!! Like this!
Al Bundy? Young man´s future choice We know the end…? Peg.. - make dinner! Marry girl It is however possible to leave a selection component empty.
Rules of Christmas Checks his slade Santa Claus X-mas day Gives one gift * While gifts not 0 not 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 *
Paint house - an iteration Paint House Get paint * While painter not satisfied with color Paint with Brush * While entire house not painted not JSP
Now you can begin to paint Get paintBegin to paint Paint House An iteration can only contain one repeated component Get one can of paint Paint with Brush * * While painter not satisfied with color While entire house not painted Iterations Iteration components OK !
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.
BubleSort algorithm in psdeudocode 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 Example of pseudocode …