Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.

Similar presentations


Presentation on theme: "1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2."— Presentation transcript:

1 1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2

2 2 Topics Software quality Design principles Production principles Sample Problem: Bingo –Analysis –Assumptions and Limitations –Modules and data flow –Data representation

3 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

4 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

5 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).

6 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...)

7 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

8 8 Recall: Software Development Cycle AnalysisDesignImplementTest Maintain documentation of the system throughout the entire cycle.

9 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

10 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

11 11 A 5 x 5 grid. Each square is a cell. Bingo: The Game Board "cell" The central cell is marked initially.

12 12 1-1516-3031-4546-6061-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

13 13 Contains 75 numbered balls. Bingo: The Jar 1 234 5 etc...

14 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

15 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

16 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

17 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

18 18 is winning board? Player Jar true or false rows and columns Game Board pick ball Game Master number call out number mark board number marked cell Data-flow diagram during game:

19 19 ask for N (i.e. the number of players) ask for names of N players initialize player scores to 0 What are the program's tasks? Initialization: At the start of the program... Algorithm:

20 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)

21 21 main Structure Chart (Draft): Main (shows control coupling only) initialize program print all scores end program options menu play game

22 22 Structure Chart (Draft): Main (shows control coupling only) main initialize program print all scores end program options menu play game

23 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

24 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

25 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

26 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

27 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

28 28 Structure Chart (Draft): Version 1 (shows control coupling only) main start play print board call out number update player initialize jar fill board

29 29 update player Structure Chart (Draft): Version 1 (shows control coupling only) mark board check diagonals check rows check columns

30 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.

31 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.

32 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.

33 33 game player board Data Representation What are the "objects" in Bingo? cell jar ball called number

34 34 game player board Data Representation cell jar ball called number Variables of type int

35 35 player board Data Representation: Cell cell int cell; #define MAX_VAL 75 Each cell normally contains an integer between 1 and MAX_VAL.

36 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.

37 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.

38 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

39 39 typedef struct { BingoBoard board; } PlayerInfo; player board Data Representation: Player cell

40 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

41 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

42 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

43 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).

44 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

45 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.


Download ppt "1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2."

Similar presentations


Ads by Google