Lecture 19. Topics: Chapter 9. Simulation and Design Moving to graphics library Unit Testing 9.5 Other Design Techniques

Similar documents
Python Programming: An Introduction to Computer Science

Lecture. Simulation && Design. Richard E Sarkis CSC 161: The Art of Programming

Beyond programming. CS 199 Computer Science for Beginners Spring 2009 Lois Delcambre Week 5/12/2009 1

CPSC 427: Object-Oriented Programming

STUDENT LESSON A14 Boolean Algebra and Loop Boundaries

Function Call Stack and Activation Records

Basics of Programming with Python

Introduction to Computer Programming for Non-Majors

CPSC 427: Object-Oriented Programming

Intro. to Computing. Lecture 7 Page1

C Functions. 5.2 Program Modules in C

COMP 110 Programming Exercise: Simulation of the Game of Craps

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Object-oriented Programming Project

12/22/11. } Rolling a Six-Sided Die. } Fig 6.7: Rolling a Six-Sided Die 6,000,000 Times

Consolidation and Review

6.S189 Homework 2. What to turn in. Exercise 3.1 Defining A Function. Exercise 3.2 Math Module.

EAS230: Programming for Engineers Lab 1 Fall 2004

CIS 194: Homework 11. Due Thursday, April 5. Risk. The Rand StdGen monad

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

CSci 1113 Lab Exercise 5 (Week 6): Reference Parameters and Basic File I/O

CSC101 - BMCC - Spring /22/2019. Lab 07

(Python) Chapter 3: Repetition

Lecture 04 FUNCTIONS AND ARRAYS

Program #7: Let s Play Craps!

Programming Assignment #4 Arrays and Pointers

PYTHON PROGRAMMING. John M.Zelle. Wartburg College AN INTRODUCTION TO COMPUTER SCIENCE SECOND EDITION

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

assertion: A statement that is either true or false.

ProgrammingAssignment #5: Let s Play Craps!

Discrete Mathematics 2 Exam File Spring 2012

Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015

Lecture Object-Oriented Design. Richard E Sarkis CSC 161: The Art of Programming

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

CMSC 201 Spring 2018 Project 2 Battleship

Introduction to Computing Lecture 09: Functions (Part II)

LAB: WHILE LOOPS IN C++

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Architecture Diagrams

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section:

SOFTWARE UNIT 1 PART B C O M P U T E R T E C H N O L O G Y ( S 1 O B J A N D O B J 3-2)

Introduction to: Computers & Programming: Review prior to 2 nd Midterm

Computational Complexity and Implications for Security DRAFT Notes on Infeasible Computation for MA/CS 109 Leo Reyzin with the help of Nick Benes

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

Functions and Recursion

Using the Command Line

IT 374 C# and Applications/ IT695 C# Data Structures

C++ How to Program, 9/e by Pearson Education, Inc. All Rights Reserved.

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

Program development plan

MONIKA HEINER.

CME 112- Programming Languages II. Week 1 Introduction, Scope Rules and Generating Random Numbers

Document Requirements

Loop structures and booleans

Information Security

Decisions: Logic Java Programming 2 Lesson 7

CS1110 Lab 6 (Mar 17-18, 2015)

Familysearch.org. Gordon Rouse 2017

8. DEALING WITH RANDOMNESS

COP 1220 Introduction to Programming in C++ Course Justification

OPERATING SYSTEMS AND APPLICATIONS

JAVASCRIPT LESSON 4: FUNCTIONS

CSE 21 Summer 2017 Homework 4

Lab 1 Implementing a Simon Says Game

Unit II. (i) Computer Programming Languages

Today CISC124. Building Modular Code. Designing Methods. Designing Methods, Cont. Designing Methods, Cont. Assignment 1 due this Friday, 7pm.

Adding content to your Blackboard 9.1 class

Systems Analysis and Design in a Changing World, Fourth Edition

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

Error Handling in C++

Functions!!! Why functions? Functions provide good way to design systems!

econnect Baccarat User Guide EC7 June 2017

OBJECTS AND CLASSES. Examples. You and I are instances of the class of objects known as people.

COMMOM OBJECT ORIENTED LISP SYSTEMS

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week!

CSE 203A: Randomized Algorithms

Student Responsibilities. Mat 2170 Week 9. Notes About Using Methods. Recall: Writing Methods. Chapter Six: Objects and Classes

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Discrete-Event Simulation:

Unit 13. Linux Operating System Debugging Programs

CS839: Probabilistic Graphical Models. Lecture 10: Learning with Partially Observed Data. Theo Rekatsinas

Mat 2170 Week 9. Spring Mat 2170 Week 9. Objects and Classes. Week 9. Review. Random. Overloading. Craps. Clients. Packages. Randomness.

CS1800 Discrete Structures Final Version A

Section 4.2: Discrete Data Histograms

CS 161 Computer Security

The Debug Perspective in Eclipse for Python A Reference and Tutorial

CSE 118 Introduction to Design

THINGS WE DID LAST TIME IN SECTION

(With a few XP tips thrown in for good measure)

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

Welcome! Graphics Fundamentals. Lecture 2. Welcome! Lecturer: Jacco Bikker

Lab 1 Implementing a Simon Says Game

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Excel VBA. Microsoft Excel is an extremely powerful tool that you can use to manipulate, analyze, and present data.

CSCI-1200 Data Structures Fall 2017 Lecture 13 Problem Solving Techniques

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

h(p://ihm.tumblr.com/post/ /word- cloud- for- hci- human- computer- interacbon CS5340 Human-Computer Interaction ! January 31, 2013!

Some announcements. Announcements for game due (via ) on Wednesday, March 15 Homework 6 due on March 15 Exam 3 on March 17

Transcription:

Lecture 19 Topics: Chapter 9. Simulation and Design Moving to graphics library 9.4.1 Unit Testing 9.5 Other Design Techniques 1

9.4.1 Unit Testing When we finish writing a function (a component of a program) it is good to give it a good testing. This process is called unit testing. Testing each function independently makes it easier to spot an error. By the time we get around to testing the entire program, chances are that everything will work smoothly. 2

9.4.1 Unit Testing When we finish writing a function (a component of a program) it is good to give it a good testing. This process is called unit testing. Testing each function independently makes it easier to spot an error. By the time we get around to testing the entire program, chances are that everything will work smoothly. Separating concerns through a modular design makes it possible to design sophisticated programs. 3

9.4.1 Unit Testing When we finish writing a function (a component of a program) it is good to give it a good testing. This process is called unit testing. Testing each function independently makes it easier to spot an error. By the time we get around to testing the entire program, chances are that everything will work smoothly. Separating concerns through a modular design makes it possible to design sophisticated programs. Separating concerns through unit testing makes it possible to implement and debug sophisticated programs. 4

9.4.1 Unit Testing When we finish writing a function (a component of a program) it is good to give it a good testing. This process is called unit testing. Testing each function independently makes it easier to spot an error. By the time we get around to testing the entire program, chances are that everything will work smoothly. Separating concerns through a modular design makes it possible to design sophisticated programs. Separating concerns through unit testing makes it possible to implement and debug sophisticated programs. These programs work will less overall effort and far less frustration. 5

9.4.1 Unit Testing racquetball game we should test the following methods/functions: 1. input() 2. simonegame(pa,pb) 3. simngames(n,pa,pb) 4. report(n,winsa,winsb) 6

9.5 Other Design Techniques Sometimes we can get stuck with the top-down design (i.e. cannot refine one of the steps; or the original specification is so complicated that refining it level-by-level is way too hard) Another approach to design is to start with a simple version of a program (or a program's component) and then try gradually add features until it meets the full specification. 7

9.5 Other Design Techniques The initial stripped-down version is called a prototype. Prototyping often leads to a sort of spiral development process: we design, implement and test a prototype, then new features are designed, implemented and tested, and we make many mini-cycles through the development process as the prototype is incrementally expanded into final program. 8

9.5 Other Design Techniques The initial stripped-down version is called a prototype. Prototyping often leads to a sort of spiral development process: we design, implement and test a prototype, then new features are designed, implemented and tested, and we make many mini-cycles through the development process as the prototype is incrementally expanded into final program. Spiral development is particularly useful when dealing with new or unfamiliar features or technologies. It is helpful to try it out - just see what can we do. Sometimes for novice programmer everything 9 may seem new, so prototyping might prove useful.

9.5 Other Design Techniques It is important to note though that spiral development is not an alternative to top-down design. They are complimentary approaches. When designing the prototype, you will still use the top-down techniques. Later you'll see another design techniques. 10

9.5 Other Design Techniques I used the code of racquetball.py and converted it to graphics: See racquetballgraphics.py 11

Lecture 18 In-class assignment 3 12 Craps game Craps game is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses. If the roll is 7 or 11, the player wins. Any other initial roll causes the player to roll for point. That is, the player keeps rolling the dice until either rolling a 7 or re-rolling the value of the initial roll. If the player re-rolls the initial value before rolling a 7, it s a win. Rolling a 7 first is a loss. We want to write a program to simulate multiple games of craps and estimate the probability that the player wins. For example, if the player wins 249 out of 500 games, then the estimated probability is 249/500 = 0.498 or 49.8%. User will be prompt for the number of games.

Lecture 18 In-class assignment 3 Sketch of the main function: def main(): Intro() # print an introduction n = getinput() # get input from the user # simulate n games, # return the result of simulation wins = simngames(n) report(n,wins) # report back to the user 13

Lecture 18 In-class assignment 3 main n n wins wins Intro get-input simngames report simonegame roll 1 0 roll value 14 structure chart

Lecture 18 In-class assignment 3 Craps game In-class and homework assignment: implement the text version of the craps game make it fool proof (take care of bad input) you may work in groups Optional: make graphics version (after you finish working on the text version) 15