1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

45
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    222
  • download

    1

Transcript of 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

Page 1: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

1

CSE1301Computer Programming:

Lecture 25Software Engineering 2

Page 2: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

2

Topics

• Software quality

• Design principles

• Production principles

• Sample Problem: Bingo– Analysis– Assumptions and Limitations– Modules and data flow– Data representation

Page 3: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

3

Software Quality• What is Software Quality?

– Programs run correctly every time and unexpected errors do not occur

– Changes/Updates are easy to add to the software

– The user understands how to use the software without too much work on their part

• Why?– To ensure things work the way they should– To save time and money in the long run– To make it easy to update the software

Page 4: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

4

Software Quality Features• Correctness and Reliability

– satisfying the requirements, level of trust

• Efficiency– obtaining the desired goal with a limited use of

resources (such as time or hardware)

• Modifiability– possibility of adapting software to changes in

requirements, and to correct errors

• Reusability– having modules which may be useful in other

applications, thus avoiding repetition

Page 5: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

5

Design Principles

Recall:• Modular

– Divide the system into manageable units.

• Highly cohesive – Elements inside a module should be highly-

related in purpose.

• Loosely coupled– Maximize independence between modules.– Avoid implicit coupling (such as the use of

global variables).

Page 6: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

6

Production Principles

Recall

• Design top-down– Break problem down into manageable sub-

problems.

• Build bottom-up– Code and test the simplest components first.– Test each component before using them to

build more complex components.(continued...)

Page 7: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

7

• Development incrementally– Make simplified versions first. – Add and test one functionality at a time, so that it

evolves into a complete system.

• Document as you go along, from the start– System documentation: describes the software's

internal composition (e.g. Pre- and Post-conditions of functions, struct definitions, etc.)

– User documentation: describes how to use the software.

Production Principles

Page 8: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

8

Recall: Software Development Cycle

Analysis Design Implement Test

• Maintain documentation of the system throughout the entire cycle.

Page 9: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

9

Write a program to play the game Bingo

• Problem specification: – What are the requirements of the system?– How do you play the game Bingo?– What are the program's tasks in the game?– What’s involved?– Who’s involved?

Analysis

Page 10: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

10

• What's involved?– Bingo Game Boards– A Jar of numbered balls

• Who's involved?– The Game Master – An N number of Players

(Note: There can be a number of variations of the Bingo game. We will look at one version.)

The Game of Bingo

Page 11: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

11

• A 5 x 5 grid. Each square is a cell.

Bingo: The Game Board

"cell"

• The central cell is marked initially.

Page 12: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

121-15 16-30 31-45 46-60 61-75

6

15

5

13

9

18

23

17

29

27

31

40

42

34

58

47

51

59

57

70

71

66

62

67

• The boards have random numbers assigned to cells in the ranges shown (each number can appear at most once only.)

• The central cell is marked initially

Range for

each column

Page 13: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

13

• Contains 75 numbered balls.

Bingo: The Jar

1 2 3 4

5 etc...

Page 14: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

14

• At the start of game:

– Puts all balls into the jar.

– Shakes the jar to mix.

• During the game:– Takes a randomly-selected ball from the jar.

– Calls out the number on the ball.

– Note: The balls taken out are not returned back to the jar until the next game.

Bingo: The Game Master

Page 15: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

15

• At the start of game:– Fills the game board randomly (according to rules).

• During the game:– Marks a cell on the game board if it contains

the number called out by the Game Master.

– Checks if the board has winning positions--i.e. if there is a row, column or main diagonal where all the cells have been marked.

– Calls out "Bingo!" if it is a winning board.

Bingo: The Player

Page 16: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

16

Bingo: Sample Winning Boards

6

15

5

13

9

18

23

17

29

27

31

40

42

34

58

47

51

59

57

70

71

66

62

67

6

15

5

13

9

18

23

17

29

27

31

40

42

34

58

47

51

59

57

70

71

66

62

67

6

15

5

13

9

18

23

17

29

27

31

40

42

34

58

47

51

59

57

70

71

66

62

67

Page 17: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

17

• Winner is the first player who has a winning game board.– Q: What if several players have winning boards?– A: It depends. Usually, the first player to call out

"Bingo!" is the winner. Another option is to divide the prize equally among those with winning boards.

• The game ends when either:

– there is a winner, or...

– the jar is empty.

Bingo: End of Game

Page 18: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

18

is winning board?

Player

Jar

true or false

rows and columns

Game

Board

pick

ball

Game Master

number

call out

number

number

mark board

number

marked cell

Data-flow diagram during game:

Page 19: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

19

ask for N (i.e. the number of players)ask for names of N playersinitialize player scores to 0

What are the program's tasks?• Initialization: At the start of the program...Algorithm:

Page 20: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

20

loop{ ask what the user wants to do if ( user wants to start all over again ) { re-initialize program } else if ( user wants to play ) { play game here } else if ( user wants to see scores so far ) { print all scores } else if ( user wants to quit ) end program /* say goodbye and all that */}

What are the program's tasks? (cont)

Page 21: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

21

main

Structure Chart (Draft): Main(shows control coupling only)

initialize program

print all scores

end program

options menu

play game

Page 22: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

22

Structure Chart (Draft): Main(shows control coupling only)

main

initialize program

print all scores

end program

options menu

play game

Page 23: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

23

place and mix all numbers in jar fill N game boards randomly print out all N game boards while ( ( no player has won yet ) and ( the jar is not yet empty ) ) {

call out a random number from jar update game boards for all players print out all N game boards }

if ( there is a winner ){ announce winner

add one to winner’s score }

Algorithm to Play Game

Page 24: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

24

Write a Program to Play Bingo... (cont)

• Start with a simple version of the problem

• Define the assumptions and limitations of this version

• Break into manageable modules

• Write algorithms and structure charts for each module

Page 25: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

25

• Number of boards per player.– Assume: Only one board per player.

• Filling game boards randomly.– Should each player have unique boards?– Assume: No need to verify that the players fill

their boards out differently.

• Multiple winning boards.– Assume: All players with winning boards get a

score each.

Assumptions and Limitations

Page 26: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

26

• Limited functionality.– Version 1: Only one player can play.– Version 2: Allow N players.

• Possible future enhancements.– Allow several boards per player.– Players can play over network (so that first player

with winning board to press “Bingo!” wins). – Graphic user interface so players can mark board

themselves.

Assumptions and Limitations

Page 27: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

27

place and mix all numbers in jar fill game board randomly print out game board while ( ( player has not won yet ) and ( the jar is not yet empty ) ) {

call out a random number from jar update player’s game board print out game board }

if ( player has won ){ announce winner

add one to player’s score }

Version 1: Algorithm

Page 28: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

28

Structure Chart (Draft): Version 1(shows control coupling only)

main

start play

print board

call out number

update player

initialize jar

fill board

Page 29: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

29

update player

Structure Chart (Draft): Version 1(shows control coupling only)

mark board

check diagonals

check rows

check columns

Page 30: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

30

So far…

• Drafted a design– wrote the algorithm for main task– divided the main task into modules– prepared structure charts

• Note: The data-flow diagrams, structure charts and algorithm become part of the documentation.

Page 31: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

31

Still to do...

• System details– data representation – identify data coupling of the modules

• Implement and test incrementally– Review the analysis and the design

• Continue software development cycle until software satisfies the requirements.

Page 32: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

32

Data Representation

• Identify shared "objects" in the system, and how to represent information about them in the program.

• Produce a common data dictionary of type definitions for the different modules.– In C, the type definitions are usually stored in a

shared header file (bingo.h). The header file is #include-d by the members in their test programs during development.

– Keep possible future enhancements in mind.

Page 33: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

33

game

player

board

Data Representation

• What are the "objects" in Bingo?

celljar

ball called number

Page 34: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

34

game

player

board

Data Representation

celljar

ball called number

Variables of type int

Page 35: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

35

player

board

Data Representation: Cell

cell int cell;

#define MAX_VAL 75

Each cell normally contains an integer between 1 and

MAX_VAL.

Page 36: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

36

player

board

Data Representation: Cell

cell int cell;

How would you indicate a marked cell?

#define MARKED_VAL 0

A cell with value MARKED_VAL indicates that it has been marked.

Page 37: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

37

player

board

Data Representation: Board

cell

struct BingoRec{ int cell[BOARD_DIM][BOARD_DIM];};

typedef struct BingoRec BingoBoard;

#define BOARD_DIM 5

Makes future modifications (large-sized boards) easy.

Page 38: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

38

/* ================================================ * * DATA: * BingoBoard * * DESCRIPTION: * A board is a grid of BOARD_DIM x BOARD_DIM * cells. * * USAGE: * Each cell normally contains an integer * between 1 and MAX_VAL. * A cell with value MARKED_VAL indicates that * it has been marked. * * ================================================ */

Data Documentation: Board

Page 39: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

39

typedef struct

{

BingoBoard board;

} PlayerInfo;

player

board

Data Representation: Player

cell

Page 40: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

40

typedef struct

{

BingoBoard board;

char name[NAME_LEN];

int isWinner;

} PlayerInfo;

Data Representation: Player

#define NAME_LEN 80

Acts as a "flag":

True or false

Page 41: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

41

/* ====================================== * * DATA: * PlayerInfo * * DESCRIPTION: * Contains a player's details and bingo board. * * USAGE: * `isWinner' is 1 if this player currently * has a winning board; 0 otherwise. * * ======================================= */

Data Documentation: Player

Page 42: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

42

typedef struct

{

/* stuff to follow */

} JarInfo;

Data Representation: Jar• Can begin development on some modules when

other modules are not yet complete.• Complete the data representation of the Jar in the

same way as the Cell, Board and Player.

jar

ball

Page 43: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

43

Data Representation: Game

typedef struct

{

PlayerInfo player;

JarInfo jar;

int calledNumber;

} GameInfo;

• Encapsulates all the information needed for Bingo (Version 1: one player only).

Page 44: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

44

Summary

• Software Quality– Why?– What?

• Design Principles• Production Principles• Example: The game Bingo

• Analysis• Data flow, modules and structure charts• Data representation and documentation

Page 45: 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

45

Readings

• Brookshear (5/e or 6/e): Chapter 6• Additional:

– S. Ceri, D. Mandrioli and L. Sbattella. The Art and Craft of Computing. Addison-Wesley, 1998. Chapters 20 to 24.