11.1 Designing Issues - PowerPoint PPT Presentation

About This Presentation
Title:

11.1 Designing Issues

Description:

system manuel: for system maintenance people. detailed ... user manuel. how system is to be operated. written at the level of expertise of the operator ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 27
Provided by: CIT788
Category:

less

Transcript and Presenter's Notes

Title: 11.1 Designing Issues


1
Lecture 11. Design, Testing and Documentation
  • 11.1 Designing Issues
  • 11.2 Debugging
  • 11.3 Testing
  • 11.4 Checking
  • 11.5 Documentation

2
Designing
  • Top-down Design in OOP
  • Data abstraction
  • classes and objects
  • member functions
  • hide data as private
  • Polymorphism
  • allow commonly used member functions to have the
    same name but perform according to class of an
    object

3
OO Programming with C
  • Top-down Design
  • break tasks down into subtasks and write a
    function for each
  • make it easy for a team to work on large software
    projects
  • Functional abstraction function as a black box
    so users only need to look at the function
    prototype and comments to use the function.
  • Function prototype tells programmers
    pre-conditions and post conditions for
    arguments(parameters) to function.

4
Design of the Elevator
  • Functions to use
  • showelevator() //show elevator include the door .
  • //pre-conditions there is no input. The inputs
    are the member variables of the class. door
    --decides the wide of the gap. Door25 if the
    door is closed. Door 3 if the door is open. The
    process of opening a door is the process of
    changing the value of door. Other required
    variables, k-- the vertical position of the
    elevator. Position--the h-position of the
    elevator.
  • ///post-conditions the elevator is drawn.

5
Design of the Elevator
  • Functions to use
  • erease() // erease the elevator. Draw black
    lines just for the door and the elevator, not for
    the skeleton. //pre-conditions are the same as
    selevator(). //post-conditions door is ereased.
  • Stop() //stop will control the door to stop step
    by step. //pre-conditions k--the vertical
    position and s--stands for if the door is really
    stopped. (both k and s are member variables.)
  • //post-condition k and s may be changed. Stop()
    will be called many times. A door will be closed
    automatically once s1. To this this, is
    simple, doordoor-1.

6
Design of the Elevator
  • Functions to use
  • close()// to change the value of door to close
    the door step by step. //pre-conditions the
    value of door in used, a member variable close
    is used. Close 0 if the door is not completely
    closed. Close 1 if the door is completely
    closed. //post-conditions the value of door is
    changed if the door is not completely closed. The
    value of door is not changed if the door is
    completely closed and close is set to be 1.

7
Design of the Elevator
  • The main function
  • test if the elevator need to be stopped
  • if yes, call stop()
  • test if the elevator need to move
  • if yes, (a) call close(), and then change the
    position oof the elevator, i.e., kk-1 or kk-1.
  • Selevator()
  • delay(300)
  • erease()
  • repeat

8
OO Programming with C
  • ADT abstract data types programmer using the
    data type does not have access to details of how
    the values and operations are implemented.
  • interfacehow to use ADT (for user)
  • implementation how the interface is is realized
    as C code.
  • tips hide member variables as private
  • access functions to access necessary data.

9
Programming Practice
  • Art ? Science?
  • Programming languages change all the time,
    focusing on different aspects of programming
    techniques.
  • Even Experts do not agree on details of
    programming style. E.g.,
  • How to pair up parenthesis ? Do we line them up
    on the same column? Do we indent every pair which
    encloses an inner loop.

10
Programming Practice
  • Criteria
  • reliable
  • maintainable
  • user friendly
  • re-usability
  • Good programming techniques are language
    independent. However, OO Languages provide useful
    tools to make it easier.

11
Readability and comprehensibility
  • Naming
  • named entities in programs
  • constants, variables, classes, objects,
    functions, files
  • use meaningful names
  • names of objects should be closely related to the
    corresponding real world entities
  • use more than one word, upper and lower case,
    delimiter characters
  • avoid ambiguities, cryptic abbreviations,
    unrelated names, single-letter identifies

12
Readability and comprehensibility
  • Divide Program into logically meaningful groups
  • class/object for logically related entities
  • functions important/related pieces of program
  • files related functions and classes.
  • Write pre-conditions and post-conditions in
    comments for function prototypes/function bodies.

13
Readability and comprehensibility
  • Use indentations (consistently and correctly) to
    indicate program structures
  • Use header file to
  • define classes and prototype member functions
  • store constants and global variables
  • Use Makefile to compile programs in different
    files and organize team project.

14
Debugging/Testing/Checking
  • Debugging Try to locate errors
  • Grammar Errors
  • Run Time Errors
  • Testing Searching for errors.
  • developer tests (gently) for delivery of good
    product.
  • expert tester tries to break product for quality
    guarantee.
  • Checking Make sure the output for an input is OK
  • an extra function accompanying a function
    which checks for correctness of the output for
    every run of the function.

15
Debugging
  • Grammar Errors Usually a good programming
    language comes with compiler tools which locate
    (usually the first occurrence of) errors.
  • Run Time Errors.
  • Tools in Turbo C
  • trace statements are executed line by line
  • break point execution stops at the line a break
    point is set
  • Print-out statements print out values of
    certain variables to see if execution goes as
    expected

16
Debugging An Example
  • original function
  • int summation(int x, int y)
  • int z
  • zx-y
  • return z
  • printout statements added to DEBUG
  • int summation(int x, int y)
  • int z coutltltx ltltxltlt y ltltyltltendl
  • zx-y cout ltlt z ltlt z
  • return z

17
Testing
  • Testing process
  • top-down testing
  • bottom-up testing
  • real-time thread testing
  • White Box Testing knowing all codes and apply
    path testing
  • exhaustive testing make sure all paths are
    executed at least once
  • selective testing chooses some paths to test
  • Black Box Testing compare the output of the
    program with the expected output for many inputs.

18
Testing Process
  • Top-down testing usually for functionality
  • Test in order of top level system, sub-system,
    module...
  • Bottom-up testing
  • test functions at the lowest level and work up
    hierarchy
  • Real-time thread testing
  • real time systems consist of co-operating
    processes and maybe interrupt driven
  • external events may cause control transfers.
  • thread testing identifies and executes each
    possible thread (of control flow of processes.)

19
Input Data for Testing
  • Choose input data according to the empirical
    distribution
  • Choose degenerated patterns of data
  • For the example of sorting function
  • all data are the same value
  • input of size 0/1/2
  • Choose simple patterns of data
  • For the example of sorting function
  • input already sorted
  • input are reversals of a sorted list

20
Checking
  • Make sure the output for an input is OK
  • Write a checker function accompanying a
    function which checks for correctness of the
    output
  • Invoke the checker function for every run of the
    original function.
  • For the sorting function as an example write an
    function to check the output of the sorting
    function is indeed sorted and check if the output
    data are the same as the input data

21
An Example for Checking
  • sort(A,n)
  • old_sort(A,n) //input is an array A of size n
    and output //is in the same array A but
    sorted.
  • if (!check(A,n)) report-error()
  • int check(A,n)
  • int I
  • if (n1) return TRUE
  • for (I0 Iltn-1 I)
  • if AIgtAI1 return FALSE
  • return TRUE //here we only check A is sorted.
    In reality //we need also check the output array
    contains the same //set of elements as the input.

22
An Example for Checking
  • max(A,n)
  • int tmp
  • tmpold_max(A,n)
  • if (!checkmax(tmp,A,n)) report-error()
  • int check(int a, int A, int n)
  • int I
  • if (n1) return TRUE
  • for (I0 Iltn-1 I)
  • if AIgta return FALSE
  • return TRUE

23
Another Example for Global Variables
The roots of a quadric equation ax2bxc0 are
x1 (-b( b2-4ac))/2ac x2x1 (-b- (
b2-4ac))/2ac includeltiostream.hgt float x1,
x2 int flag0 void roots(float a, float b,
float c) void main(void) roots(1.0,2.0,
1.0) if(flag 0) coutltltThe
roots areltltx1ltltx2 else coutltltNo
real root
void roots(float a, float b, float c) if
(bb-4acgt0)
x1(-bsqrt(bb-4ac))/(2ac) x2
(-b-sqrt(bb-4ac))/(2ac) else
flag1 x1, x2 and flag are used
as global variables. Otherwise, roots must return
two values that we do not know how to do it.

24
More about Equation
Write a function that returns two roots of an
equation ax2 bx c 0. Write
a function that checks if the roots a correct.

25
Documentation Description of control software
system
  • functional specification
  • design specification
  • system manuel
  • for system maintenance people
  • detailed description of system structure/component
  • user manuel
  • how system is to be operated
  • written at the level of expertise of the operator
  • system integration tests and test results

26
Flow Chart
Beginning of game display the board
Player 2s next move
Display the new board
yes
no
Player 1s next move
Does it kill some stones?
resign
Display the new move
End of the Game
Choose a move
yes
no
Note only flow chart of player 1 is displayed
and that of player 2 is similar.
Is it legal
Write a Comment
User Comments (0)
About PowerShow.com