250 likes | 392 Views
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. Get dressed. Eat breakfast. Go to school. Division. Time. Structure diagram. By 2IT Data students …. ”Morningwhile has gold in mouthd”. Morning routine.
E N D
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 Get dressed Eat breakfast Go to school Division Time Structure diagram By 2IT Data students … ”Morningwhile has gold in mouthd”
Morning routine Get dressed Eat breakfast Go to school Time 8:00 am 8:02 am 8:05 am Sequence (order in time) Sequence Sequence parts
Morning routine Get dressed Eat breakfast Go to school Find clothes Put clothes on Take from Ask girlfriend wash basket where clothes are Structure diagram ”Morningwhile has gold in mouthd” Division Time
What colour on your socks? If blue doesn’t exist,but pink does If blue exists Else Blue Pink White Selection Selection Selection parts
Morning routine Get dressed Eat breakfast Go to school Find clothes Put clothes on Many glasses of beer Take from Ask girlfriend One glassof beer wash basket where clothes are Structure diagram ”Morningwhile has gold in mouthd” Division Time
Drink beer (lightbeer) Many glassesof beer One beer Iteration (repetition) Iteration As long as you’re thirsty Iteration part
Morning routine Get dressed Eat breakfast Go to school Find clothes Put clothes on Take a cab Run Many glasses of beer Take from Ask girlfriend One glassof beer One step wash basket where clothes are Structure diagram ”Morningwhile has gold in mouthd” Division Time
Morning route Get dressed ELSE Search clothes IF you find basket Get from laundry Ask girl/boyfriend basket Put on the clothes Eat breakfast Eat one pancake WHILE pancakes <> 0 Go to school IF money = 0 ELSE Run Take a cab Move foot one step WHILE distance to school <> 0 Flow chart Flowcharts are onedimensional. They are used when you have to describe exactly how the code is processed. The Structure diagram is easier to follow.
A 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? Car A has to make a selection B
Selection Red signal Green signal STOP DRIVE Left blinker No blinker Right blinker Drive left Straight ahead Drive right Crossinga selection of directions How can you see in which direction the car in front of you will choose? Crossing
Young man´s future choice Marry girl Marriage - a selection? not JSP
Marry girl Be free!! Like this! 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 We know the end…? Peg.. - make dinner! Al Bundy? It is however possible to leave a selection component empty. Young man´s future choice
While gifts not 0 * Checks his Gives one slade gift Rules of Christmas Santa Claus X-mas day not JSP
First Last Checks his Hands out gifts slade This is CORRECT!! While gifts not 0 * Gives one gift Santa changed his mind • Parts connected to the same component must be of similar type Santa Claus X-mas day
While painter not satisfied with color While entire house not painted * * Get paint Paint with Brush Paint house - an iteration Paint House not JSP
Iterations Get paint Begin to paint While painter not satisfied with color While entire house not painted * * Get one can of paint Paint with Brush OK ! Iteration components Now you can begin to paint • An iteration can only contain one repeated component Paint House
JSP-editor Henrik Engström JSP-editor
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 Example of pseudocode … while not at end of listcompare adjacent elementsif second is greater than firstswitch them get next two elementsif elements were switchedrepeat for entire list