1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)

Slides:



Advertisements
Similar presentations
© Glenn Rowe AC Lab 2 A simple card game (twenty- one)
Advertisements

10 Software Engineering Foundations of Computer Science ã Cengage Learning.
Chapter 2: Modularization
PLANNING THE TIC TAC TOE GAME BY NEEL DAVE. TIC TAC TOE INSTRUCTIONS Tic Tac Toe Instructions The basic concept of Tic Tac Toe 1.This is a game for two.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Representing a Game Board In a game, we represent the action taking place using an array – In a very simple game, we use individual variables to represent.
1 CSE1301 Computer Programming Lecture 25: Software Engineering.
Software Engineering and Design Principles Chapter 1.
1 CSE1301 Computer Programming Lecture 26: Case Study.
BINGO! Topic Create Your Game Card You will need a blank piece of paper.
CS 536 Spring Global Optimizations Lecture 23.
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
CSE 115 Week 12 March 31 – April 4, Announcements March 31 – Exam 8 March 31 – Exam 8 April 6 – Last day to turn in Lab 7 for a max grade of 100%,
CSE1301 Computer Programming: Lecture 27 Game Programming: Bingo.
CSE1301 Computer Programming: Lecture 21 Software Engineering.
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.
© The McGraw-Hill Companies, 2006 Chapter 16 Two-dimensional arrays.
2015 Pre-Release Practice Click the button to try a random exam-style question. Click on the reveal button to check your answer.
Fundamentals of Python: From First Programs Through Data Structures
1 CSE1301 Computer Programming: Lecture 25 Group Project: "Hunt the Wumpus”
CS102 Introduction to Computer Programming
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
System Implementation System Implementation - Mr. Ahmad Al-Ghoul System Analysis and Design.
Fundamentals of Python: First Programs
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
MOM! Phineas and Ferb are … Aims:
Announcements.
11 Finding Winners Using Arrays Session 8.2. Session Overview  Find out how the C# language makes it easy to create an array that contains multiple values.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
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.
Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
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.
Chapter 7 Software Engineering. © 2005 Pearson Addison-Wesley. All rights reserved 7-2 Chapter 7: Software Engineering 7.1 The Software Engineering Discipline.
Chapter 7 Software Engineering Introduction to CS 1 st Semester, 2015 Sanghyun Park.
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.
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.
Hoppers. 11 Create a circle – call out 1,2 or 3 11 is eliminated How can we adapt the task?
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
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.
Software Engineering Principles Dr. José M. Reyes Álamo.
1 CSE1301 Computer Programming Lecture 24: Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
The Hashemite University Computer Engineering Department
Systems Design.  Application Design  User Interface Design  Database Design.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
Guide to Programming with Python Chapter Six Functions: The Tic-Tac-Toe Game.
Checkers A Matlab Project by Spenser Davison, Edward Dyakiw, Justin Pezzi, and Scott Wu.
2-dimensional Arrays A 2-dimensional array has rows and columns It is actually an “array of arrays” A Tic-Tac-Toe board is an example of a 3 by 3 2-d array.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
MOOR ERROR HANDLING Types of error How to test your code for errors How to detect errors How to recover from errors.
1 CS 177 Week 13 Recitation Writing Complex Programs.
Possible exam questions with Scenarios
Lecture 7: Repeating a Known Number of Times
Software Design Lecture : 9.
The Alpha-Beta Procedure
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Data and Flowcharts Session
Data and Flowcharts Session
Informatics 122 Software Design II
Presentation transcript:

1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)

2 Topics Software quality Design principles Production principles Sample Problem: Bingo

3 The A-Team: Sample Problem: Bingo I want a program for playing "Bingo"! Amy Dave ??? Mr. Grouch

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

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

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 –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 Write a Program to Play Bingo... Amy Dave ??? How do we start?

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

10 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?

11 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. The A-Team will have to follow Mr. Grouch's version.) The Game of Bingo

12 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 only.) Range for each column

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

15 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

16 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

17 Bingo: Sample Winning Boards

18 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

19 Draw a 5x5 grid on a piece of paper. "Randomly" fill in your board, with numbers from the correct ranges. Swap boards with your neighbour. Example Game

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

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

22 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?

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

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

25 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

26 Write a Program to Play Bingo... Amy Dave ??? Help! We’re overwhelmed by the task!

27 Write a Program to Play Bingo... Amy Dave ??? Start off with a simpler version of the problem!

28 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

29 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

30 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

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

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

33 mark board update player check rows check columns check diagonals Structure Chart (Draft): Version 1 (shows control coupling only) Er... I’m doing these modules ???? To be continued...

34 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, Chapters 20 to 24.