The Software Development Cycle

Paul Scarrone

Two Truths & a Lie

  1. A program with syntax errors can execute but might produce incorrect results.
  2. Although the syntax of programming languages differs, the same program logic can be expressed in different languages
  3. Most simple computer programs include steps that perform input, processing, and output

Understand the problem

The checking account problem

Plan the logic

Planning Logic

The Symbols

Inputs and Outputs

(Variables)

x = 4
x + 1 = 5

Pseudocode

set x = 4
output x + 1

JavaScript

var x = 4;
alert(x + 1);

Another way of looking at it

x = "Paul"
"My name is " + x = ?

Pseudocode

set x = "Paul"
output "My name is " + x

JavaScript

var x = "Paul";
alert("My name is " + x);

One Step Further

x = "Paul"
y = "My Name is "
y + x = ?

Pseudocode

set x = "Paul"
set y = "My Name is "
output y + x

JavaScript

var x = "Paul";
var y = "My Name is ";
alert(y + x);

Processing

Time to take some action

(Sequence) My cup of coffee

Sequence Pseudocode
Start
  Boil kettle
  Add coffee to cup
  Add boiling water
  Add milk
  Add sugar
End
JavaScript (Does not run)
boilKettle();
addCoffeeToCup();
addBoilingWater();
addMilk();
addSugar();

(Selection) Decisions

Condition
If (you are) happy then
  clap
else
  (you should) frown.

How do you like your Coffee

Selection Pseudocode
Start
  Boil kettle
  Add coffee to cup
  Add boiling water
  If Milk required?
    Add milk
  End If
  If Sugar required?
    Add sugar
  End If
End
JavaScript (Does not run)
boilKettle();
addCoffeeToCup();
addBoilingWater();

if(milk === true){
  addMilk();
}

if(sugar == true){
  addSugar();
}

(Loop) Repetition

Repeating yourself

Loop Pseudocode
Start
  Output "How many sugars?"
  Input sugars
  Set added = 0
  Loop
    If added == sugars ?
      Add sugar
      Set added = added + 1
    End If
  End Loop
End
Javascript (Does not run)
var sugars = prompt("How many sugars?", 0); //Output and Input in one command
var added = 0;
while(added < sugars){
  addSugar();
  added = added + 1;
}

One lump or two

Two Truths & a Lie

  1. Understanding the problem that must be solved can be one of the most difficult aspects of programming.
  2. The two most commonly used logic-planning tools are flowcharts and pseudocode.
  3. Flowcharting a program is a very different process if you use an older programming language instead of a newer one.

Let's Try it

Draw a flowchart and its pseudocode to represent a program that allows the user to enter values for the width and length of a room's floor in feet

The program outputs the area of the floor

One Possible Solution

One solution
Start
  Read height
  Read width
  Set area = height * width
  Output area
End
JavaScript (You can try it and change the values)
var height = prompt('Enter Height in Feet', 0);
var width = primpt('Enter Width in Feet', 0);
alert(height * width)

Review

Putting them together

Identify the parts

Identify the parts

Lets build our own

Buying and planting flowers in the spring
if we are planting flowers this year then
  buy flowers in pots
  while frost is still possible
    if it is over 50F today then
      bring potted flowers outdoors for the day
    else
      keep potted flowers inside for the day
    end if
  end while
  plant flowers in ground
end if

Two Truths & a Lie

  1. Each structure in structured programming is a sequence, selection, or loop.
  2. All logic problems can be solved using only three structures-sequence, selection, and loop.
  3. The three structures cannot be combined into a single program.

Try it on your own

Draw a flowchart and its pseudocode to represent a program that will take 5 coffee orders

You will ask each person if they want decaf

You will ask each person if they want milk

We will review it on Monday

What is Structured Code

The Rules

  • A structured program includes only combinations of the three basic structures.
  • Each of the structures has a single entry point and a single exit point.
  • Any structures can be stacked or connected to one another at their entry and exit points.
  • Any structure can be nested within another structure.

The Reason for Structure

  • Clarity - As programs get bigger, they get more confusing if they are not structured.
  • Maintenance - You and other programmers will find it easier to modify and maintain structured programs as they change in the future
  • Modularity - Structured programs can easily be broken down into modules that can be assigned to other programmers. Modules can be reused.

Example of unstructured code

Two Truths & a Lie

  1. Some processes cannot be expressed in a structured format.
  2. An unstructured flowchart can achieve correct outcome.
  3. Any unstructured can be 'detangled' to become structured.

Let's Try It

You are concerned that your car has a flat tire. Standing outside the car how do we identify and/or replace a leaky tire?