|
Home | Résumé | Courses | Contact | Useful Links | Favorite Links | USC - Homepage |
Introduction to Programming - (CPTR125) - Lectures
Nassi-Schneiderman diagrams
Nassi-Schneiderman diagrams is another way of representing algorithms. One thing it does not allow is a GOTO. It is a diagrammatic approach to algorithm design, but not as bulky to draw as flowcharts.
The Three Basic Control Structures
Our programs are made up of the three basic constructors of: sequence, selection, and repetition.
1 Sequence
The sequence control structure is defined as the straight forward execution of one processing step after another. Here is the general form of a sequence.
![]()
Here is a typical sequence of statements.
![]()
2 Selection
The selection control structure can be defined as the presentation of a condition, and the choice between two actions depending on whether the condition is true or false. Here is the general form of the selection construct.
![]()
Here is a typical selection statement.
![]()
Here is a selection with a empty false side.
![]()
3 Repetition
The repetition control structure can be defined as the presentation of a set of instructions to be performed repeatedly, as long as a condition is true. Here is the general form of repetition.
![]()
Here is the general form again.
![]()
Here is a repetition control structure with typical statements.
![]()
Simple Algorithms That Use the Sequence Control Structure
Here are the examples from chapter 3 using Nassi-Schneiderman diagrams.
Example 3.1 Add three numbers
A program is required to read three numbers, add them together and print their total.
A Defining diagram
Here is the IPO (Input, Process, Output) chart.
![]()
B Solution algorithm
Here is the algorithm as a Nass-Schniederman diagram.
![]()
Example 3.2 Find average temperature
A program is to get the maximum and minimum temperatures for a day and calculate and display the average temperature.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the algorithm as a Nassi-Schneiderman diagram.
![]()
Example 3.3 Calculate mowing time
A program is required to read in the length and width of a lot, and the length and width of the rectangular house that has been built on the lot. Then it computes and displays the mowing time the lot.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the algorithm as a Nassi-Schneiderman diagram.
![]()
N-S Diagrams and the Selection Control Structure
Here are the examples from chapter 4 using Nassi-Schneiderman diagrams.
Simple IF statement
Simple selection occurs when a choice is made between two alternative paths.
![]()
Null ELSE statement
The null ELSE structure is a variation of the simple IF structure with the false side being empty.
![]()
Combined IF statement
A combined IF statement is one that contains multiple conditions in the decision symbol.
![]()
Nested IF statement
A nested IF statement has another IF in either the true or false branch.
![]()
B Non-Linear nested IF statement
A non-linear nested If in a Nassi-Schneiderman diagram does make it obvious as to where each else clause is paired with a then clause.
![]()
Simple Algorithms That Use the Selection Control Structure
Finally here are the examples from chapter 4 rewritten as Nassi-Scheiderman diagrams.
Example 4.1 Read three characters
An algorithm prompts the operator for three characters, gets the characters, sorts them and outputs them in ascending order.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the algorithm as a Nassi-Schneiderman diagram.
![]()
Example 4.2 Process customer record
A program reads a customer's name, purchase amount, and a tax code. The tax code is validated, the sales tax is computed along with the total. very thing is printed out.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the algorithm as a Nassi-Schneiderman diagram.
![]()
Example 4.3 Calculate employee's pay
A program is to read payroll records, compute an employee's pay, and print out everything.
A Defining diagram
Here is the IPO chart for the program.
![]()
B Solution algorithm
Here is the solution algorithm as a Nassi-Schneiderman diagram.
![]()
The CASE Structure Expressed as an N-S Diagram
The CASE statement is great for a test that has many acceptable answers. Here is one way to represent a CASE statement in a Nassi-Schneiderman diagram.
![]()
Example 4.4 Process customer record
A program is to read customer records, validate the tax code, compute the sales tax and total and print out everything but the tax code.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the solution algorithm as a Nassi-Schneiderman diagram.
![]()
N-S Diagrams and the Repetition Control Structure
Repetition is used to repeat a group of instructions 0 or more times. It makes for economic programming. Here is the DOWHILE in a Nassi-Schneiderman diagram.
![]()
Simple Algorithms That Use the Repetition Control Structure
Here are some algorithms from chapter 5 rewritten as Nassi-Schneiderman diagram.
Example 5.1 Fahrenheit-Celsius conversion
A program is to get 15 Fahrenheit temperatures and convert them to Celsius and display them with a "all temperatures processed" message.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the solution algorithm rewritten as a Nassi-Schneiderman diagram.
![]()
Example 5.2 Print examination scores
A program is to read and print a series of student's names and exams scores. Then it is to print the average score..
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the Solution algorithm as a Nassi-Schneiderman diagram.
![]()
Example 5.3 Process student enrolments
A program is to read a student records file and print out only the records of students taking Programming I course.
A Defining diagram
Here is the IPO chart.
![]()
B Solution algorithm
Here is the Solution algorithm as a Nassi-Schneiderman diagram.
![]()
Example 5.4 Process inventory items
The program is to read an inventory file and produce a low stock items report.
A Defining diagram
Here is the IPO chart
![]()
B Solution algorithm
Here is the Solution algorithm as a Nassi-Schneiderman diagram.
![]()
Required reading: Simple Program Design - Lesley Anne Robertson - Appendix 2.
Used with permission - Copyright © 2005 by James L. Fuller - Simple Program Design - Lesley Anne Robertson - Course Technology.
|
Home | Résumé | Courses | Contact | Useful Links | Favorite Links | USC - Homepage |