I'll go back to program lodging in and dine in this section we'll be discussing how to much allow the program all right we're going to begin with the structure of a modular program in such a program the main program provides the main line logic which is your basic steps which actually accesses the modules which are in your program let's review the three parts of a module you get your module header which includes the identifier and possibly other important identifying information then you've got your module body which contains all the statements in the body then you've got your module return statement this marks the end of the module and identifies the point at which control returns to a program or module that called the module in other words you're going straight back to your main line logic very important to include the return statement in this course even though some program level languages the logic will still be have a return statement much naming our modules is similar to naming a variable now module names are followed by a set of parentheses please note that module names should follow similar conventions to variable names and that module names are commonly followed by a set of parentheses especially in Java and C++ and C sharp please note that the parentheses are empty in this course a good idea is to use a verb to name the module since it is performing some action example gate or calculate or display when a main program wants to use a module or method you've created it calls the modules name now we use a in the flowchart we use a symbol cord used to call a module is a rectangle with a bar across the top like such place the name of the module you are calling inside the rectangle such as say - name followed by open closed brackets within a rectangle and you've got your line across at the top of the rectangle draw each module separately with its own scent cymbals remember Sentinel cymbals are our diamond shapes let's run through figure 2.3 where we are going to be focusing on a program that produces a bull using only a main program now in Chapter one we did similar examples if in our exercises as such we have our declarations which is name and balance we're going to input our name and balance and what actually happens with input is that we're actually going to have prompts like please enter name please enter balance these have been a meta chair just to keep it the example kind of short for you but you will learn more about prompts later in this chapter so we're going to output ABC manufacturing that is our heading which we are busy outputting of here then we're going to output 47 Park Lane and then we're going to output Umrah West whatever and their zip code and output customer F followed by name so what's going to happen is over here is that we are going to be calling on our box of memory what is stored in name is going to be outputted here for us as such so what we're going to do is I'm going to create ourselves a little box of memory and this box the memory here is called name and this little box that made me here is called balance so what we're going to do is we're going to now input our contents within our box so computer's gonna run we're going to get a please enter a name and we're going to enter John John is going to go within our name variable then it's going to prompt please enter balance ok Mitzpeh enter 75 then it's going to up with ABC manufacturing which is yeah and then it's gonna output our 47 Parklane and then it's going to output Amuro and the zip code and then it's going to output customer : and what's going to be calling it's going to be calling the contents of name what is the contents of name contents of name is John so it's going to output John hem and then is going to up with the total of balance what is my balance my balance is 75 that is the content of my variable balance and we're going to output balance which is 75 now you can ask how are we going to modulus this program so we're going to need to take statements out of the main program and put a module into a module we are going to actually encapsulate those statements so the statements we're going to be taking out is our outputs so we're gonna take our outputs out and we're going to encapsulate them within our module over here I want you to think of marginalization as a capsule when I talk about encapsulation I'm talking about a capsule now when I talk about it capsule I'm talking about a little tablet and if you had one of those capsule tablets at Barnardo's you can you can take it apart and all the contents spell out well that's basically what encapsulation is is that we are storing contents within a capsule and our capsules name is display address info and that's the modules name and once the contents are spelt out we're going to return back to the main program so our main program is becoming shorter and it's easier to understand as you can see here and also modules are reusable we can use the display address info in another program if we had another program which needed to display the outputs of different things you would just have to change the output statements that needed that needs to be done so when statements contribute to the same job we get greater functional cohesion this basically means that there is no set of rules to use when we have to moduli a program that's what the term functional cohesion is this applies to selecting the particular program statements they make up the module like we selected this area here to make a per module please read the following article on cohesion just give you a better understanding of what creation is we will be discussing more I'm designing modules for higher cohesion in Chapter nine with next semester it will also explore the topic of coupling which is a measure of how much modules depend on each other to take as marginalisation just one step further we can declare in the beginning have closed declaration within our module of line 1 line 2 line 3 note that these line 1 line 2 line 3 is named constants they're all in uppercase so we've put them at beginning of our module here and therefore we can change it right at the beginning of a module membered this is a simple program imagine either to change things at the beginning so if you're going to have upward line 1 line 2 line 3 rather just declare them at the beginning as strings and you just uh put the named constants as you can see these ones are local variables there are in scope of just this module here so basically our modules are self-contained units that are easily transported there are portable from one program to the next to the next to the next we'll have to discuss global variables and constants they are declared at the program level in your mainline logic and they visible to and usable in all the modules called by the program and many programs actually avoid global variables to actually minimize errors so if you can see here these declarations these variables name and balance are global variables because we input name and balance and we want to call on name and balance later on in our program if you have a look here we want to be able to call on our name and balance in our output statements you could very well have another module an output module of customer and you can just input name to the address and output to an output module as well or get details a Manor logic of almost every procedural computer program follows a general struction declarations for global variables and constants housekeeping tasks detailed loop tasks and end of job tasks if you can have a look at figure 2 point 6 you'll see this is will be yours and procedural program at typical procedural program for your mainline logic you will have your sensible value in your decision here you'll have your detailed loop method or module you'll have your housekeeping module which is start with and you'll have your end of job now I like a good analogy of this is when you go to a factory your housekeeping would be within your housekeeping module would be turn on the lights turn in the machines get everything ready to start the production of the day and then you start your loop that would be with your detailed loop what's happening in your detailed loop let's say we're making chocolate bars it will be make the make the chocolate cool the chocolate down in the molds wrap the chocolates up put them in boxes and that will be our detailed loop which will carry on and on and on and on and then when our end of jump our end of job will be the end of the day what do you do the end of the day you switch off the machines you switch off the lights there's will be your end of the jobs you up you will probably output how many chocolates you made for that particular day that will be your end of job please join me in the next video where we discussing creating hierarchy charts