Modular Programming - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Modular Programming

Description:

incorporate modularity into the design process ... to calculate the length of a hypotenuse of a right angled triangle, given the ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 14
Provided by: sandyg
Category:

less

Transcript and Presenter's Notes

Title: Modular Programming


1
Modular Programming
  • Summer Institute for Computer Studies Teachers
  • August 2001

2
From the curriculum
  • incorporate modularity into the design process
  • write subroutines that pass parameters and use
    local and global variables
  • describe the purpose of functions and procedures,
    and how they are expressed in a programming
    language

3
From the curriculum contd
  • describe the parameter passing and scope
  • identify the differences between local and global
    variables
  • manipulate numbers and text using built in
    subroutines

4
What is a module?
  • a.k.a. subprogram, function/procedure, method,
    subroutines
  • one, clearly defined purpose
  • should be small - less than 20 lines - no more
    than two levels of nesting
  • almost always has parameters

5
How important is modularity?
  • It is the most important programming/problem
    solving skill in the grade 11 course.
  • Students need as much exposure and practice as
    possible.
  • Modularity should be incorporated with other
    curriculum expectations wherever possible.

6
Design and use of modules in other expectations
  • At the low level
  • bottom up
  • investigating repetition structures using
    animation
  • investigating selection structures by writing
    Boolean functions (a.k.a. predicates)
  • At the high level
  • top down
  • steps of the problem solving model
  • planning
  • implementation
  • testing
  • maintenance
  • approach each from a modular point of view

7
Progression of modular coding...
  • use existing subprograms
  • recognize the relationship between actual and
    formal parameters
  • write the body of a subprogram given a header
  • write a small program given stubs
  • design small programs involving subprograms with
    parameters
  • design large programs which can be divided among
    several programmers

8
Use existing subprograms ...
  • A sample problem using character graphics and
    built-in string subroutines
  • Write a subprogram called scroll which will make
    a word scroll across the screen from left to
    right.
  • Variations
  • Let the user enter the word.
  • Pass the word as a parameter to scroll.

9
Develop good habits early.
  • as soon as possible, have students write
    subprograms rather than programs
  • subprograms with parameters make solutions more
    flexible
  • For example
  • Write a procedure to calculate the length of a
    hypotenuse of a right angled triangle, given the
    lengths of the other two sides.

10
Parameter passing ...
  • actual parameter - used when calling the
    subprogram
  • formal parameter - used in the header of the
    subprogram
  • parameters may be passed by value or passed by
    reference
  • students must be able to follow the flow of
    control

11
What is a stub anyway?
  • subprogram header - name, parameter list, return
    type
  • internal documentation
  • code which outputs the defined purpose of the
    subprogram (usually one line)
  • default return type (if necessary)
  • should be easily derived from the planning stage
    of the problem solving process

12
Modularity and OO-Design
  • objects have attributes and behaviours
  • record fields can be analogous to attributes
  • subprograms can act as behaviours
  • create assignments which model objects
  • for example write a program that will simulate a
    digital watch or clock
  • time set
  • increment time
  • display in different formats

13
Assignment ideas
  • small
  • medium
  • large
Write a Comment
User Comments (0)
About PowerShow.com