Chapter 1 Analysis and Design

Page last updated 08/23/99

 

Goals of the chapter

Exercises, Analysis and Design Projects

 

 

 

 

1.1 Program Development

Step Process Deliverables
Analysis Understand the problem A document that lists the useful data objects
Design Organize the solution An algorithm that outlines a solution
Implementation Get the solution running An executable program

 

 

 


1.2 Analysis

Synonyms of analysis

Activities of analysis

  1. Read and understand the problem statement.
  2. Name the pieces of information necessary to solve the problem.

Active Learning Example

Compute the maximum airplane takeoff weight.

 

 


There is more to these data than just the names

The data things are called objects and have these three important characteristics:

How are these objects used?

 

 

 

 


Example of Analysis

Find the length of a line segment.

The line is represented by Cartesian coordinates of its end points, e.g. (1,1) to (5,4)

The formula for the length of a line segment is ch1a1.gif (1144 bytes) = 5

What are input variables and output variables? ____________________________________

 

 


More Examples

Consider the following problems.  What variables would be necessary in the solution?  Choose useful names and give a sample value for each.  Would that variable be used as input or output?

Problem Description Object Name / Sample Data Input or Output?
Compute the average of three test scores


   
Compute the roots of a quadratic equation: ax2 + bx + c

   
Compute a loan payment


   

 

 

 


Summary of Analysis

Activities performed during analysis

 

 

 

 

 

 


Analysis Example

Using the grade assessment scale (weighted average) below, compute the weighted average for any combination of two tests and a final.

Objects Sample Problem 1 Sample Problem 2 Input or Output
 

 

     
 

 

     
 

 

     
 

 

     

 

 

 


1.3 Design

Synonyms of design: model, think, plan, devise, pattern, propose, outline

We'll use these design tools:

Algorithms

An algorithm is a set of activities that solves a problem.

An algorithm must:

 

 


Algorithm Example

Bake a Cake

 

 

 


1.3.1 Algorithmic Patterns

IPO Algorithmic Pattern

Pattern:  Input/Process/Output (IPO)

Problem situation: The program requires input to generate the desired info.

Outline of IPO:

  1. obtain input data from user
  2. process input data
  3. output the results

 

 

Patterns ala Alexander

"Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice."

From A Pattern Language, Christopher Alexander, Oxford University Press

 

 

 

 

 

1.3.2 Example of Algorithm Design

The deliverable from this design phase will be an algorithm.

The IPO patterns provides a guide to design this more specific algorithm (that is a bit sketchy:

IPO Model One Specific IPO Case Study

I)nput Obtain test1, test2, and finalExam
P)rocess Compute the course grade
O)utput Display the course grade

Refinement

Usually a number of steps must be refined into substeps.

For example, Compute the course grade might now be refined with the C++ mathematical addition + and multiplication * symbols and names for the objects:

courseGrade = test1 * 0.25 + test2 * 0.25 + finalExam * 0.50 ;

 

 

 

 


1.3.3 Algorithm Walkthrough

Suggestion: Use an algorithm walkthrough to review the algorithm

Simulate what the computer would do if given the instructions.

 

 

 

 

 

 

An example walkthrough

Input) Retrieve some example values from the user and store them into the objects as shown:

Processing) Retrieve input data and compute courseGrade as follows

courseGrade=(0.25*test1)+(0.25*test2)+(0.50*finalExam)

(0.25*80.0) + (0.25*90.0)+(0.50*100.0)

(20.0 + 22.5 + 50.0)

courseGrade = 92.5

Output) Show course grade to the user:

Note: Retrieve the data stored in courseGrade to show: 92.5%