Computer program‎ > ‎

### An example of process in steps - Pseudo code

 To wrote a program that will enable computer to simulate specific process we must first understand the process and have it broken down to basic steps, which we will line up in proper order. For a description of each step in the process we use an ordinary spoken language, the simpler the better for the further study of the process. When the entire description of the steps is agreed in a specific order and steps are definitely numbered, we obtain the pseudo code which is then used to develop programs that will simulate the investigated process. Remember what is a Computer program.   Here we shall do that in one simple example.   PROCESS OF MAKING TEA Think of ways to prepare tea.We need the court for warm up the water (pot), the court for tea consumption (cups), heating body (hotplate), certain type of tea, water and time.The process consists of the following steps:1. Take the pot2. Pour water into the pot3. Put the pot on the heating body4. Turn on the hotplate and wait for water to boil5. Put tea in a cup  6. When the water boils in a pot, pour the water over tea into a cup and wait 10 minutes7. Turn off the hotplate8. Drink tea   On this basis, to prepare the tea it was necessary only 8 steps that are executed in the above mentioned sequence. Is this true and is this correct sequence of steps ?Of course not. To arrive at a precise definition of steps and their sequence is required much more detailed analysis.For example what if the pot is hollow or there is no water or no electricity. Whether is to first turn off hotplate and then remove the pot?Now we know that we have not defined any step that leads to making tea process break because of a lack or an undesirable case in the process.    Let's try again: 1. Take the pot1.1 If the pot is hollow end process2. Do you have the water2.1 If there is water pour water into the pot2.2 If there is no water stop the process3. Put the pot on the heating body4. Do you have electricity4.1 If there is electricity turn on the hotplate and wait for water to boil4.2 If there is not stop process 5. Put tea in a cup  6. When the water boils in a pot, pour the water over tea into a cup and wait 10 minutes7. Turn off the hotplate8. Is 10 minutes passed 8.1 If not go to step 88.2 If yes process is continued , next step9. Drink tea   In this sequence of steps we have defined the steps that allow the process to terminate in the event of a shortfall. This is done by asking questions and offering answers that determine the future course of the process (steps of 1.1., 2, 2.1.  2.2, 4, 4.1.  4.2), it is usually called in programming conditional branching (If. .. then. else ..). Finding and defining this type of steps in the process is critical and extremely important because if you can not find any possibility that the process is complete as it should for some strange reason, the program that was later derived from the pseudo code-a will not be good. Occurs the case , for example, negative value under the square root, or attempted division by zero, or even blocks because of the impossibility of further execution. In steps 8, 8.1 and 8.2 is so called iteration (repetition until conditions fulfilled), which means that step 8 is repeated until the condition is fulfilled. In the real computer program it is called a Loop. Of course watching the pseudo code we come to the conclusion that we could introduce the steps of the process "Start" and "End" of the process, and that all steps that require interruption of the process should be directed to the end of the process step.   Well then:   0. Start of the process 1. Take the pot1.1 If the pot is hollow , go to Step 102. Do you have the water2.1 If there is water pour water into the pot2.2 If there is no water,  go to Step 103. Put the pot on the heating body4. Do you have electricity4.1 If there is electricity turn on the hotplate and wait for water to boil4.2 If there is not, go to Step 10 5. Put tea in a cup  6. When the water boils in a pot, pour the water over tea into a cup and wait 10 minutes7. Turn off the hotplate8. Is 10 minutes passed 8.1 If not,  go to step 88.2 If yes process is continued , next step9. Drink tea 10. End of the process       Now, we are within PSEUDO CODE defined something called a conditional jump (or jump action) on the step when the condition is satisfied. Study the steps 1.1, 2.2, 4.2 and 8.1 and get conclusion how our process works. Also try to define yourself steps to restart the process based on previously acquired knowledge. If you do not know how see a solution.   The solution: You should establish the steps 9.1, 9.2 and 9.3. 9.1 Do you want to cook tea again9.2 If you do , go to step 09.3 If you do not , go to step 10   Step 9.3 is not necessary becouse it relates to the latest step in a series and therefore, if the condition is not met, an affirmative answer to the question in step 9.1, the process ends automatically by moving to step 10 This pseudo code can be written for each observed process, provided that you understand its mode of operation,after which you can make the appropriate computer program.Try to create a pseudo code for solving a mathematical problem. Let's solve quadratic equations.  All the best, Author
Comments