Transcript for:
Program Logic and Design: Pseudocode and Flowcharts

welcome back to program logic and design in the section we're going to be discussing our pseudocode statements and our flowcharts alright so what we're going to be chatting about is pseudocode now what is pseudocode pseudocode is an English lack representation of the logical steps it takes to solve a problem so if we have a look at our making a cup of tea here we organize everything together we plug in the kettle we put the tea bag in the cup we put the water into the kettle we wait for the kids or to boil we add water to the cup we remove the tea bag with a tea spoon or a fork we add milk or sugar depending on our preferences and then we serve it is in a logical order and we haven't eliminated some of the important steps like boiling the kettle alright next we have our flowcharts flowchart is a pictorial representation of the logical steps it takes to solve a problem if we have a look at our problem here it is pictorial I'll discuss all the different shapes for you and what they mean later but just what you need to know is that you go lamp doesn't work ok lamp doesn't work is it plugged in if it's not plugged in then we plug it in if it is plugged in then we're gonna check the bulb is the bulb burned out yes it is we replace the bowl if it's not then we repair the lamp then something's definitely wrong with the lamp now I'd like you to think of pseudocode and flowcharts as of a map when you'd give a friend directions to your house you the friend would either write down the directions you turn left at this row to turn right at this road and on your right hand side will be my house with the number 2 or 3 or whatever it is or you will draw the map literally draw it you'll draw the road you will draw this road into sexless rodents as roads called this road and in you probably draw a v' flow line on how to get to your house on the roads which you have drawn so that's basically what pseudocode m and flow chance is it depends on what your client prefers and most clans prefer flow trusts because it's more pictorial it's more an understanding for them is pictures alright let's discuss how we actually write pseudocode pseudocode representation of our number doubling what we have is we've got start we input on my number we set my own Z equal to my number times two I put my answer we stop we've really discussed it but what I want to show you is the standards or writing pseudocode your programs begin with start and end with stop these two words are always aligned if you have a look start and stop remember you can also use begin or end it's your preference as long as it's understandable and they are aligned next is each program statements performs one action for example input processing output alright so input my number we process my answer using my number multiplied by 2 and we output my own zone see how they're all directly aligned underneath each other program statements are indented a few spaces more than the start all the module name alright we'll discuss modules later but you can see if few spaces is indented from that I as you can see I've actually left out the second and the third one we'll discuss that when we do to module ization which is much later now each program statements appears on a single line if possible when this is not possible continuation lines are indented so we will have there on a new line and if this was a la processing you will just indent a few spaces and then carry on writing ok you'll see this later when you do in when we write bigger programs program statements begin with lowercase letters this is why I like it guys using notepad plus plus because you won't have a problem of auto capitalization which microsoft word does for you you can always right click on I'll show you later right click on a drop-down menu to make sure that it doesn't have the auto capitalization but I'll show you that later all you need to know now is just please make sure that everything is lowercase and last but not least is no punctuation is used to end statements so there's no full stop off to stop the or end which brings us to drawing flowcharts now these are our flow lines they connect shapes with arrows you Georgia magic shapes that contain the individual statements because that's how you create a flow chart if you have a look at my input symbol my input symbol is a Palillo grammar and if you remember them like the shape is called from maths but this is Apple Illig RAM it indicates an input operation and my processing symbol contains processing statements such as arithmetic like my answer equals set my number miles papa to and it is a rectangle my output symbol is the same as my input symbol it is a parallelogram and it represents our output statements our flow lines which is the arrows it's a line with an arrow shows our direction and they this connects our steps our terminal symbols is start stop begin int they are terminal symbols we terminate our pseudocode or web programming with a start and we've terminated with stop start and stop symbols they shape like a race track and we also call them a lozenge so a lozenge is like a tablet so a lozenge is more fancy word for a tablet join flowcharts our continuation is he has an example of our doubling a number program which we've done did previously we have our lozenge which is our start it's our terminal segment start to stop then you have your flow lines which says ok farm starts you flow towards map Liljegren which is my input my number which is our input then we process so my flow line goes towards my processing here which is nice my arms are we processing what my arms is going to be which is my number whatever we input it in multiplied by 2 then we flow towards our output answer I'll put my answer and that's also Palillo Graham for pseudocode we will just go start in put my numbers set my number my answer to equal to my number x 2 i'll put my answer stop indented dented new line new line new line new line new line lower case lower case lower case lower case lower cases now I would like you to think all right which is the better tool for learning programming is it flowcharts or is it pseudocode is a very interesting article which I have given you on the structure flow line niche what they actually did is they took a couple of students and they said to them which do you prefer do you prefer structured flowcharts which is a complex algorithms using a graphic method or do you prefer verbal method like pseudocode like writing english in like an english like manner and what was interesting is that seventy-five to eighty nine percent of the students actually preferred flowcharts and then they went on to say okay how strongly do they actually feel about flood shots please have a read through this article it's just a little bit of an abstract version of it it's quite interesting to see what people actually think about float ron's you might some of your mind actually thinks that pseudocode is better or flowcharts is better but it is a personal preference in the long run to be honest i've preferably the first pseudocode because it's kind of it's like programming but for my clients they prefer flowcharts because it's more graphical and they understand it a lot better than what me writing like a code like english language pseudocode repeating instructions all right now program in Figure 1.6 yes one point six the flowchart in pseudocode for the doubling of number this only works for one number it's not feasible to run the program over in over 10,000 times it's not feasible to add 10,000 lines of code to a program either so what we actually do is we create a loop which is a repetition of a series of steps in state and you could see when you creatively we've got to avoid having an infinite loop and an infinite loop is basically when your flow of logic never ends it just goes on and on and on and on and on but if you have a look at you go 1.7 this is insufficient code you'll see that there's like a little bubble here there's a you you would never want to write such a repetitious list of instructions so we input my number we we set my uncertainty we create a new number and we create a new on see we uh put it on okay it's a new number imagine doing this nine hundred nine thousand nine hundred ninety seven more more times it's repetitious of code which is not needed what would be easier is to create a loop if you have a look at the flow line add my answer we go up go back to that flow line just before the input man number and then we start that process again we loop it again process now the this is also floor because what happens is that it's going to keep going over and over and over without ending how are you going to make this end it brings me to your next video which is using a sentinel value to end a program