You are on page 1of 31

Sequential Logic Structure: In depth

• An algorithm is a set of instructions telling the computer how to process a module in a solution.
• Write an algorithm for each module in a program.
• A flowchart is a visual illustration of an algorithm. So draw a flowchart to accompany each
algorithm.
• The Pseudocode will follow the flowchart.
• The coupling diagram shows the relationship between the modules and the flow of data
• The data dictionary lists the variables and their definitions.
Sequential Logic Structure: In depth
• Algorithm Instruction : Start module name list of parameters (module number)

• Flowchart symbol:

• Definition (Action associated with the Instruction): Start processing a module.

• eg calculate_result(p,c,m)
Sequential Logic Structure: In depth
• Algorithm Instruction : Enter list of variable names

• Flowchart symbol:

• Definition (Action associated with the Instruction): Enter data from a data block or from the
keyboard into the following variable memory locations.

• eg enter out_of_mks
Sequential Logic Structure: In depth
• Algorithm Instruction : Variable = expression

• Flowchart symbol:

• Definition (Action associated with the Instruction):


• Assign the value of the expression to a variable location.
• This is called an assignment instruction.
• A module may be processed as part of an expression, if there is a return value.

• eg total = p+c+m
perc = total * out_of_mks/100
Sequential Logic Structure: In depth
• Algorithm Instruction : Write list of variable names

• Flowchart symbol:

• Definition (Action associated with the Instruction): Write to the printer (output device) the
values represented by the following variable names.

• eg write total perc


Sequential Logic Structure: In depth
• Algorithm Instruction : Process module names (list of parameters)

• Flowchart symbol:

• Definition (Action associated with the Instruction): Execute the instructions in the named
module, and then return to execute the next instruction.
Sequential Logic Structure: In depth
• Algorithm Instruction : End/Exit

• Flowchart symbol:

• Definition (Action associated with the Instruction):


• Stop the processing of the module.
• Processing ceases with the End
• With the Exit, processing continues with the next instruction after the Process
Sequential Logic Structure: In depth
• Algorithm Instruction : Return (variable)

• Flowchart symbol:

• Definition (Action associated with the Instruction):


• Stop the processing of the module
• place the value of the variable in the module name, and continue with the instruction containing the module call.
Algorithm, Flowchart and Pseudocode example
• Read and print two values
Organising Tools to solve a problem
1. The problem analysis chart—helps you define and understand the problem, develop ideas for the
solution, and select the best solution.
2. The interactivity chart—breaks the solution to the problem into parts.
3. The IPO chart—helps define the input, the output, and the processing steps.
4. The coupling diagram and the data dictionary designate the data flow between modules. The data
dictionary records information on the items.
5. The algorithms define the steps of the solution.
6. The flowcharts are a graphic form of the algorithms.
7. The pseudocode presents a generic language representation of the algorithm.

These charts are aids to the efficient development of a well-written program.

They will not be perfect the first time around and will often need several revisions.
Example of Sequential problem : All steps
Problem: Mary Smith is looking for the bank that will give the most return on her money over the
next five years. She has $2,000 to put into a savings account. The standard equation to calculate
principal plus interest at the end of a period of time is
where,
P Principal (amount of money to invest, in this case $2,000)
I Interest (percentage rate the bank pays to the investor)
N Number of Years (time for which the principal is invested)
M Compound Interval (the number of times per year the interest is calculated and added to

the principal)
Example of Sequential problem : All steps
Step 1: Problem analysis (Using Problem Analysis Chart)
• Understand what is needed and what is given.
• Separate them from all of the nonessential information in the problem.
• Write down the input in the Given Data section and the output in the Required Results section.
• Record the processing that the problem demands in the section of the problem analysis chart
headed Required Processing.
• Write possible solutions for the problem and any ideas related to the solution in the Solution
Alternatives section.
• Generate solution ideas through brainstorming and creative thinking.
Example of Sequential problem : All steps
Step 1: Problem analysis (Using Problem Analysis Chart)

Given Data Required results


Principal—$2,000 Principal plus Interest at the end of the
Interest time period
Number of Years—5
Compound Interval (#/year)
Example of Sequential problem : All steps
Step 1: Problem analysis (Using Problem Analysis Chart)

Given Data Required results


Principal—$2,000 Principal plus Interest at the end of the
Interest time period
Number of Years—5
Compound Interval (#/year)
Required processing
Example of Sequential problem : All steps
Step 1: Problem analysis (Using Problem Analysis Chart)

Given Data Required results


Principal—$2,000 Principal plus Interest at the end of the
Interest time period
Number of Years—5
Compound Interval (#/year)
Required processing

Solution Alternatives
Enter all data as variables.
Enter principal and interest as constants and the other data as variables.
Process one bank in one run.
Process all banks in one run.
Example of Sequential problem : All steps
Step 1: Problem analysis (Using Problem Analysis Chart)

Given Data Required results


Principal—$2,000 Principal plus Interest at the end of the
Interest time period
Number of Years—5
Compound Interval (#/year)
Required processing

Solution Alternatives
Enter all data as variables.
Enter principal and interest as constants and the other data as variables.
Process one bank in one run.
Process all banks in one run.
Example of Sequential problem : All steps
Step 1: Problem analysis (Using Problem Analysis Chart)

Given Data Required results


Principal—$2,000 Principal plus Interest at the end of the
Interest time period
Number of Years—5
Compound Interval (#/year)
Required processing

Solution Alternatives
Enter all data as variables.
Enter principal and interest as constants and the other data as variables.
Process one bank in one run.
Process all banks in one run.
Example of Sequential problem : All steps
Step 2: Develop Interactivity chart
Decide various modules of the program
Given problem can be divides as:
1. The InterestControl module, which controls the solution
2. The Read module, which enters the data
3. The Calc module, which calculates the amount
4. The Print module, which prints the result
Example of Sequential problem : All steps
Step 3: Develop IPO chart from Problem analysis and Interactivity chart
How can the input be processed to achieve the required output?
Provide general instructions for the solution on the IPO chart.
Start with the output, next specify the input, and then develop the processing method required to
calculate the output from the input.

INPUT PROCESSING Module Reference OUTPUT


1.Ending
Principal and
Interest
2.All input data
Example of Sequential problem : All steps
Step 3: Develop IPO chart from Problem analysis and Interactivity chart
How can the input be processed to achieve the required output?
Provide general instructions for the solution on the IPO chart.
Start with the output, next specify the input, and then develop the processing method required to
calculate the output from the input.

INPUT PROCESSING Module Reference OUTPUT


1.Initial Principal 1.Ending
2.Interest rate Principal and
3.Number of Interest
years 2.All input data
4.No of times
interest is
compounded
yearly
Example of Sequential problem : All steps
Step 3: Develop IPO chart from Problem analysis and Interactivity chart
How can the input be processed to achieve the required output?
Provide general instructions for the solution on the IPO chart.
Start with the output, next specify the input, and then develop the processing method required to
calculate the output from the input.

INPUT PROCESSING Module Reference OUTPUT


1.Initial Principal 1. Enter data 1.Ending
2.Interest rate 2. Change interest rate Principal and
3.Number of to hundreds Interest
years 3. Calculate ending 2.All input data
4.No of times principal & Interest
interest is 4. Print required
compounded results
yearly
Example of Sequential problem : All steps
Step 3: Develop IPO chart from Problem analysis and Interactivity chart
How can the input be processed to achieve the required output?
Provide general instructions for the solution on the IPO chart.
Start with the output, next specify the input, and then develop the processing method required to
calculate the output from the input.

INPUT PROCESSING Module Reference OUTPUT


1.Initial Principal 1. Enter data 1. Read 1.Ending
2.Interest rate 2. Change interest rate 2. Calc Principal and
3.Number of to hundreds Interest
years 3. Calculate ending 2.All input data
4.No of times principal & Interest
interest is 4. Print required 3. Print
compounded results
yearly
Example of Sequential problem : All steps
Step 4: Develop coupling diagram & Data Dictionary
Which variables are passed from one module to another.
Example of Sequential problem : All steps
Step 4: Develop coupling diagram & Data Dictionary
• To determine which
variables are call-by-
reference parameters and
which are call-by-value
parameters, the
programmer needs to see
which variables will be
changed in the called
module.
• If the variable is changed,
then it needs to be a call-
by-reference parameter.
• If the called module is
going to use only the value
of the variable, then it
needs to be a call-by-value
parameter.
Example of Sequential problem : All steps
Step 5: Internal & External Documentation
• Write down important details about the program.
• What was done, how it was done, and where it was stored?
• The user needs to know what has been done and to use the program or application effectively,
make sure the processing is correct.
• Internal documentation:
• Use of remark or comment statements.
• These statements appear only in the listing of the statements and nowhere else.
• They are for the use of the programmer only.
• The end user never sees them.
• External documentation:
• Writing manuals (either printed or electronic) with detailed explanations of the program and how to use
it.
Example of Sequential problem : All steps
Step 6: Algorithm & Flowchart
• Algorithm : How can this module complete its function?
• Flowchart : How does the algorithm look graphically?
• Using the completed algorithms and the flowcharts, you can find and correct logic errors.
• Develop Algorithm for every module (Including control module)
Example of Sequential problem : All steps
Step 6: Algorithm & Flowchart
Interest Control Module
Example of Sequential problem : All steps
Step 6: Algorithm & Flowchart
Read Module
Example of Sequential problem : All steps
Step 6: Algorithm & Flowchart
Calc Module
Example of Sequential problem : All steps
Step 6: Algorithm & Flowchart
Print Module
Example of Sequential problem : All steps

Step 7: Test algorithm & Flowchart with test data

You might also like