1 CSE1301 Computer Programming Lecture 26: Case Study.

Slides:



Advertisements
Similar presentations
10 Software Engineering Foundations of Computer Science ã Cengage Learning.
Advertisements

Chapter 3: Modularization
Chapter 2: Modularization
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)
1 CSE1301 Computer Programming Lecture 25: Software Engineering.
Software Engineering and Design Principles Chapter 1.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Department of Computer Science University of Maryland, College Park
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
CSE1301 Computer Programming: Lecture 13 Documentation.
1 Lecture 9  Arrays  Declaration  Initialization  Applications  Pointers  Declaration  The & and * operators  NULL pointer  Initialization  Readings:
CSE1301 Computer Programming: Lecture 27 Game Programming: Bingo.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Chapter 1 Principles of Programming and Software Engineering.
CSE1301 Computer Programming: Lecture 21 Software Engineering.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Chapter 1 Program Design
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.
CSE1301 Computer Programming: Lecture 29 Group Project: “Quabble”
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
1 CSE1301 Computer Programming: Lecture 25 Group Project: "Hunt the Wumpus”
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
1 Copyright (C) 2008 by Dennis A. Fairclough all rights reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Chapter 6 Functions 1. Opening Problem 2 Find the sum of integers from 1 to 10, from 20 to 37, and from 35 to 49, respectively.
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Putting together a complete system Chapter 10. Overview  Design a modest but complete system  A collection of objects work together to solve a problem.
1 CSE1301 Computer Programming: Lecture 24 - Supplement Teddy’s Modules.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Programming Principles Chapter 1. Objectives Discuss the program design process. Introduce the Game of Life. Discuss object oriented design. – Information.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Chapter 7 Software Engineering Introduction to CS 1 st Semester, 2015 Sanghyun Park.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
Discussion 4. Labs public MyPoint(double xInit, double yInit ) { MyPoint p = new MyPoint(0, 0); } ClassProblem.java recursive java.lang.StackOverflowError.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
The basics of the programming process The development of programming languages to improve software development Programming languages that the average user.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
1 CSE1301 Computer Programming Lecture 24: Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
(3-1) Functions II H&K Chapter 3 Instructor - Andrew S. O’Fallon CptS 121 (September 9, 2015) Washington State University.
Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
The Hashemite University Computer Engineering Department
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
 Problem Analysis  Coding  Debugging  Testing.
Lecture 7: Repeating a Known Number of Times
Lesson 5 Functions I A function is a small program which accomplishes a specific task. For example, we invoke (call) the function, sqrt(x), in the library.
Arrays … The Sequel Applications and Extensions
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 4 Functions Objectives
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Presentation transcript:

1 CSE1301 Computer Programming Lecture 26: Case Study

2 Topics Production principles Sample problem: Bingo

3 Software Quality Features Correctness and Reliability –satisfying the requirements 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

4 Design Principles 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)

5 Production Principles 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

6 Develop 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 –System documentation: describes the software's internal composition –User documentation: describes how to use the software Production Principles (cont)

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

8 Problem specification: What are the requirements of the system? Analysis How do you play the game Bingo? What are the program's tasks in the game?

9 What's involved? –Bingo Game Boards –A Jar of numbered balls Who's involved? –The Game Master –A (number of) Player(s) The Game of Bingo

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

The boards have random numbers assigned to cells in the ranges shown (each number can appear at most once) Range for each column Bingo: The Game Board (cont)

12 Contains 75 numbered balls Bingo: The Jar etc...

13 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

14 At the start of game: –Fills the game board randomly 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 –Calls out "Bingo!" if it is a winning board Bingo: The Player

15 Bingo: Sample Winning Boards

16 The player wins when s/he has a winning game board The game ends when –there is a winner, or –the jar is empty Bingo: End of Game

17 Recall: Software Development Cycle AnalysisDesignImplementTest

18 ask for the name of the player ask for N (the number of boards for the player) initialize the player’s score to 0 What are the program's tasks? Initialization: At the start of the program

19 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 } 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)

20 main Call Structure (Draft): Main initialize program print all scores end program options menu play game

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

22 place and mix all numbers in jar fill N game boards randomly print out all N game boards while ( player has not won yet ) { pick a random number from jar update game boards for the player print out all N game boards } if ( the player won ) { congratulate the player increment the player’s score } Algorithm to Play Bingo

23 Write a Program to Play Bingo (cont) If things get too complex: Start off with a simpler version of the problem!

24 Number of boards per player –Assume: Only one board per player Scoring –Assume: No score is kept Assumptions and Limitations (Version 1)

25 place and mix all numbers in jar fill game board randomly print out game board while ( player has not won yet ) { pick a random number from jar update player’s game board print out game board } if ( the player won ) { congratulate the player increment the player’s score } Version 1: Algorithm Note that the if and the termination condition are the same

26 place and mix all numbers in jar fill game board randomly print out game board while ( player has not won yet ) { pick a random number from jar update player’s game board print out game board } congratulate player Version 1: Algorithm (cont)

27 Call Structure (Draft): Version 1 start play print board pick a number update player initialize jar fill board play game

28 update player Call Stucture (Draft): Version 1 mark board check diagonals check rows check columns

29 Software Development Cycle AnalysisDesignImplementTest

30 Data Representation Identify shared “objects” in the system, and how to represent information about them in the program Produce a data dictionary of type definitions –The type definitions are usually stored in a header file ( bingo.h ), which is shared by all the programs –Keep possible future enhancements in mind

31 game player board Data Representation (cont) What are the "objects" in Bingo? cell jar ball called number

32 game player board Data Representation (cont) cell jar ball called number Variables of type int

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

34 player board Data Representation: Cell (cont) 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

35 struct BingoRec { int cell[BOARD_DIM][BOARD_DIM]; }; typedef struct BingoRec BingoBoard; player board Data Representation: Board cell #define BOARD_DIM 5 Makes future modifications (large-sized boards) easy

36 /* ================================================ * * 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 (cont)

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

38 typedef struct { BingoBoard board; char name[NAME_LEN]; } PlayerInfo; Data Representation: Player (cont) #define NAME_LEN 80 player board cell

39 typedef struct { BingoBoard board; char name[NAME_LEN]; int isWinner; } PlayerInfo; Data Representation: Player (cont) Acts as a "flag": True or false player board cell

40 /* ====================================== * * 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

41 typedef struct { int JarArray[MAX_VAL]; int numballs; } JarInfo; Data Representation: Jar (cont) jar ball We know how to represent the jar from Lecture 21

42 Data Representation: Game typedef struct { PlayerInfo player; JarInfo jar; int calledNumber; } GameInfo; Encapsulates all the information needed for Bingo (Version 1: one player, one board)

43 Shared Data Information that modules need to share with each other May require a description of the tasks of each module

44 Call Structure (Draft): Version 1 start play print board pick a number update player initialize jar fill board play game

45 Tasks: –input player's name –set player.isWinner to False –put all balls in the jar –fill the board randomly according to rules Call Structure (Draft): Version 1 start play initialize jar fill board jar board game play game

46 Call Structure (Draft): Version 1 Tasks: if the called number is on the board: –mark the cell –check for winning rows, columns or diagonals –update player.isWinner player, calledNumber update player player play game

47 Call Structure (Draft): Version 1 pick a number number, jar jar Tasks: –select a number at random from the jar –remove the number from the jar –return the number play game

48 Call Structure (Draft): Version 1 board print board start play initialize jar fill board jar board game player, calledNumber update player player jar pick a number number, jar play game

49 Modular Development Recall: –Each module (or sub-module) is implemented as a C function –Execution of a module (or sub-module) is done with a function call It is a good idea to store the functions of each component in a separate file

50 Modular Development (cont) Identify “priority” modules Examples: –modules for initialization of shared data startPlay –modules for testing other modules printBoard -- to test fillBoard and updatePlayer –modules which will help glue the sub-modules together playGame

51 #include #include "bingo.h" /* data dictionary, #define-s */ int main() { GameInfo theGame; /* insert code for main algorithm here */ return 0; } Skeleton of Main Module

52 A "Priority" Module: Print Board board print board print cell cell value board cell

53 /* ======================================================== * NAME: * void printBoard ( BingoBoard *board ) * * DESCRIPTION: * This function is used to print out a bingo board. * printBoard() calls printCell() to print out an * individual cell. * If the cell value is equal to MARKED_VAL, then the cell * is considered marked. printCell() outputs an indicator * (such as an asterisk) if the cell is marked. * * PRE: * It is assumed that `board' points to a struct of type * BingoBoard, and that the struct has been initialized * appropriately so that the cells contain only valid * values. * * POST: * none. * ======================================================= */ Indicates that the function will not modify the board, even if the function uses a pointer "Stub" for module printBoard

54 void printCell ( int cellValue ) { if ( cellValue == MARKED_VAL ) { printf(" **"); } else if ((1 <= cellValue) && (cellValue <= MAX_VAL)) { printf("%4d", cellValue); } else { printf(" BAD"); } return; } bingo-1a-board.c

55 Testing Modules A test program is used to demonstrate that a module's implementation performs as expected Recall: Lecture 15: Flowcharts and debugging –Test data should check every possible execution path of the algorithm

56 Testing Modules (cont) Build incrementally: Once a module has been verified using the test program, you can use it to build larger modules Simulate dependencies to set controlled conditions for testing

57 #include #include "bingo.h" /* data dictionary, #define-s */ /* assumes board.c is included in the project */ int main() { /* valid boundary data */ printCell(1); printCell(75); /* special case */ printCell(MARKED_VAL); /* invalid data */ printCell(-1); printCell(76); printf("\n"); return 0; } bingo-1a-test1a.c

58 void printBoard ( BingoBoard *board ) { int row, col ; for ( row = 0; row < BOARD_DIM; row++ ) { printf("\t"); for ( col = 0; col < BOARD_DIM; col++ ) { printCell ( (*board).cell[row][col] ); } printf("\n"); } return; } bingo-1a-board.c

59 #include #include "bingo.h" /* data dictionary, #define-s */ /* assumes board.c is included in the project */ const int X = MARKED_VAL; int main() { /* We'll fill the board up just for testing. */ BingoBoard theBoard = {{ {1, 16, 31, 46, 61}, {2, 17, 32, 47, 62}, {3, 18, X, 48, 63}, {4, 19, 33, X, 64}, {5, 20, 34, 50, 65} }}; printBoard(&theBoard); return 0; } bingo-1a-test1b.c

60 System Integration Putting components together to form larger components, until the entire system is complete Often challenging in large systems where several components have to be developed by different people Documentation and Documentation/Naming Conventions

61 #include #include "bingo.h" /* data dictionary, #define-s */ /* assumes board.c., jar.c, player.c are included */ int main() { GameInfo theGame; startPlay(&theGame); printBoard(&(theGame.player.board)); while (!(theGame.player.isWinner)) { callOutNumber(&(theGame.jar), &(theGame.calledNumber)); updatePlayer(&(theGame.player)); } printf("BINGO! Congrats, %s!\n", theGame.player.name); return 0; } Code for Main Algorithm -- Version 1

62 On to Bingo -- Version 2 Several boards per player Keep the scores in a continuing game

63 Reading Brookshear (5/e or 6/e): Chapter 6