Chapter 1- Analysis and Design

¨  Class Prep: Exercise 1F on page 27.

¨  Chapter Objectives

§  Understand one simple example of program development.

§  Understand the characteristics of a good algorithm

§  See how algorithmic patterns can help in program design

§  Provide deliverables from the analysis phase of program development

§  Provide deliverables from the design phase of program development

§  Understand the relationship between a class and its objects

§  Understand objects as having a name, state, and a set of operations

¨  1.1 Program Development

¨  One program development strategy has these three steps:

¾  Analysis: Understand the problem
¾  Design: Organize the solution
¾  Implementation: Get the solution running

¨  1.2 Analysis

§  Analysis deliverable

¾  What you are to do
¾  A document that lists the useful data objects

§  Activities

¾  Read and understand the problem statement.
¾  Name the pieces of information necessary to solve the problem. These pieces of information are objects and have three important characteristics:
·  a name
·  state a.k.a value(s)
·  a set of operations to manipulate the state
¾  Decide what object(s) represent the answer—the output
¾  Decide what object(s) the user must enter to get the answer—the input
¾  Create a document that summarizes the analysis. This document is input for the next phase of program development—design

¨  1.2.1 An Example of Analysis

¨  1.3 Design:

§  Design deliverable

¾  An algorithm that outlines a solution

§  Design tools:

¾  algorithms
¾  algorithmic patterns
¾  algorithm walkthroughs

§  Algorithms

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

¾  An algorithm must:

·  list activities that must be performed
·  list the activities in the proper order.

¾  Example - bake a Cake

¨  1.3.1 Algorithmic Patterns

§  Algorithmic Pattern

¾  A pattern that occurs frequently during program development

§  The Input/Process/Output (IPO) Pattern

Pattern: Input/Process/Output (IPO)

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

Outline: 1. obtain input data from user

2. process input data

3. output the results

¨  1.3.2 Example of Algorithm Design

§  The deliverable from this design phase will be an algorithm.

§  We often need to refine some steps.

¨  1.3.3 Algorithm Walkthrough

§  Suggestion: Use an algorithm walkthrough to review the algorithm

§  Simulate what the computer would do if given the instructions

¾  If input occurs, copy values by object names

¾  If processing occurs, change an object's value

¾  If output occurs, write that output

¨  1.4 Implementation

§  Implementation deliverable

¾  An executable program

§  Once the algorithm is translated into a programming language abstraction:

¾  use the compiler to generate machine code

¾  use the linker to create executable program

¾  run the program

¾  test the program

¨  1.4.2 Testing

§  Testing occurs at any point in program development:

¾  Analysis: example problems

¾  Design: algorithm walkthroughs

¾  Implementation: run program with several sets of input data

§  A running program isn't always right!

¾  but we can gain confidence that it is by testing it thoroughly

¨  1.5 Objects and Classes

§  Objects are entities stored in memory

§  We understand an object through

¾  the value(s) it stores

¾  the operations that can be applied

¨  1.5.1 Objects

§  Characteristics of Objects

¾  Name

·  own unique name

¾  State

·  The state of the double class objects was set either through an input operation or through an assignment operation

¾  Operations applied to objects

¨  1.5.2 Classes

§  A class defines the value(s) stored by an object and the operations that may be applied to objects of that class.

§  A program may utilize many instances of the same class.

§  Each instance of class is also known as an object

§  Some standard C++ classes

¾  double

¾  int

¾  string

¾  ostream

¾  istream

¾  bool

¾  char

¾  vector