If the statements are not in that sequence, the result obtained will not be the answer intended Figure 4-1 Simple sequence The Calculate Average module is not a separate module away from the rest f the four modules below it. But it actually contains all the four modules. Each process (a rectangle) represents a component with their function/action stated in the function list. If the component does not contain or form other constructs (I. E. Other sequences, selections or iterations), it is regarded as an elementary component. The diagram should be interpreted in a top-down, left to right manner.
The Calculate- Average Module has four elementary components. Each time it is activated, it will activate the Input Number module, Calculate Sum module, Determine Average module and the Print Result module in that order. Consider another example Figure 4-2 Complex sequence The sequence of activation for the above will be A, B, E, F, C, D, G, l, J, H 4. 1. 2 Selection Construct The selection construct consists of condition(s) and one or more components. Based on the outcome for the condition(s), only one of the components will be selected. All the other components will not be selected.
JSP representation Where CLC is total points 90 CO is total points 80 CO is total points 70 CO is total points 60 Figure 4-5 Multiple selections From the JSP representation, when Check Total Points Module is activated, depending on the condition, one of the modules (either A, B, C, D or F) will be activated. If the condition Total Points 90 is true, A-Module will be activated and the process will continue at the next module after the Check Total Point Module (not shown here). If the condition is not true (I. E. False), it will then check the condition Total Points 80.
If the condition is true, a-module will be activated and the process will continue at the next module after the Check Total Points 70 and so on. The F-module does not have a condition associated with it because it takes the default condition. If all the above mentioned conditions turn out to be false, F-module will be activated. . 1. 3 Iteration Construct The iteration construct provides a way for the programmer to repeat a certain/whole portion of the program until certain condition(s) is met. (Also known as looping or repetition construct. The latter (certain condition) is important as it will ensure that the program loop will not go on indefinitely. The schematic logic for iteration could be written as Main-process Module DO WHILE Not End Of File DO Detail-process Module ENDED ENDED Each time the Main-process Module is activated, the Detailed-process Module will be executed zero to n times depending on he condition (Not End Of File). Figure 4-6 Looping/alteration/Repetition Take note of the convention. For the iteration construct, the process box is slightly different from the normal process box.
It has an asterisk 0 at the top right corner of the process box, indicating that it is an iteration construct. There is also the controlling condition. It can be the actual condition itself or a number from a conditions list. Each time the Main-process Module is activated, it will activate the Detail-process Module that may contain other sub-modules depending on the controlling condition (Not End Of File). When the Tailpiece’s Module is completed, it will then check the controlling condition again. If it is still Not End Of File, Detail-process Module will be activated again.
If the controlling condition returns a false value, it will go on to the next module (not shown here). 4. 2 Stepwise Refinement Stepwise refinement is a process to sub-divide (refine) the main program function into sub-functions. This is done progressively at each level until the lowest level functions can be represented in a programming language. In the example above (Figure 4-6), it would be difficult for the aerogramme to start coding the Tailpiece’s Module as it lacks too many details/ steps required in the target programming language.
Further refinement of the steps involved will have to be carried out. Hence the name Stepwise Refinement. On refinement, the Detail-process Module will have a few other sub-modules. (Figure 4-7) Figure 4-7 Repetition with sub-modules 4. 3 Functions and Conditions List The functions listed in the functions list serve as a further refinement to the module it is representing. It is normally represented as a sequence of actions that is achievable n the target programming language. One should take note that at this stage, we are more concerned with the design of the program rather than how to code the program.
As JSP is most suited for a High Level design, the functions listed in the functions list will normally be generalized statements. Sample entries in the functions list Functions list Open files Read a record Output all required headings Calculate average mark Set FOE-Flag to 1 As for the conditions list, all conditions associated with selections and iterations are listed separately from the structured diagram. These conditions are cross-referenced using condition numbers CLC, CO, CO, etc. Sample entries in the conditions list Conditions list CLC .
FOE-Flag is NOT 1 CO. Hrs-worked 44 CO. Average mark 50 Both the functions and conditions can be used, ( I. E. , if at some part of the JSP diagram, you need to perform or test the same condition again) you Just have to state the correct action/condition number. Your JSP diagram will look neater without the full conditions/actions written in full, on it. 4. 4 Case Study A program is needed to help a local college to grade its students. A total sighted score is determined for students from two midterm exam scores both weighted at 30, and a final exam score at 40.
A grade is assigned on the following basis Total weighted scoreGrade60F60and70D70and80C80and90B90A For each student, the program is to output the student number, the total weighted score and the grade assigned. It is also required to count the number of students receiving each of the five grades. The input will be in the form off record, each consisting of Student Number, Midterm Test 1, Midterm Test 2 and Final Test mark. The iteration is to be terminated by a suitable dummy record. The summary will then be printed showing the distribution of the grades. Draw the JSP.
As the first step, list down all the main functions that are needed to carry out the tasks as mentioned in the problem. Initialize variables (counters, accumulators) Getting records Check loop termination condition Calculate total weight score Check grade Assign grade Increase various appropriate grade counter accordingly Check page control (using line counter) Output headings Output result for each student Get next record Output summary Stop program With the main functions listed, we can start to draw the JSP. Not all the functions listed will be represented with a module (process box).
Get access to
Guarantee No Hidden