Programming Assignment #3 CS-2301, B-Term 20091 Programming Assignment #3 User-defined Functions Due, November 18, 11:59 PM (Assignment adapted from C:

Slides:



Advertisements
Similar presentations
Modular Programming With Functions
Advertisements

50.530: Software Engineering Sun Jun SUTD. Week 10: Invariant Generation.
Building Java Programs
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Event-drive SimulationCS-2303, C-Term Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The.
Chapter 5 C Functions The best way to develop and maintain a large program is to divide it into several smaller program modules, each of which is more.
FIN 685: Risk Management Topic 5: Simulation Larry Schrenk, Instructor.
True or false A variable of type char can hold the value 301. ( F )
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program Modules in C 5.3Math Library Functions 5.4Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Programming Assignment #4 CS-2301, B-Term Programming Project #4 Arrays and Pointers Due, November 24, 11:59 PM (Assignment adapted from C: How to.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2007 Pearson Education, Inc. All rights reserved C Functions.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 12 – Craps Game Application: Introducing Random.
CS 117 Spring 2002 April 5, Exam 3 April 10 –files, arrays, strings, classes –practice exams are up –review on Monday.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
C Lecture Notes Functions (Cont...). C Lecture Notes 5.8Calling Functions: Call by Value and Call by Reference Used when invoking functions Call by value.
CORE MECHANICS. WHAT ARE CORE MECHANICS? Core mechanics are the heart of a game; they generate the gameplay and implement the rules. Formal definition:
Craps!. Example: A Game of Chance Craps simulator Rules – Roll two dice 7 or 11 on first throw, player wins 2, 3, or 12 on first throw, player loses 4,
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 7: One More Loop Problem, Generating “random” values, Midterm Review.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox.
DiceRoller DiceRoller (object class) and DiceRollerViewer client class: Write a DiceRoller class (similar to Yahtzee) to: Allow the person to initially.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Chapter 5 - Functions Outline 5.1Introduction 5.2Program Modules in C 5.3Math Library Functions 5.4Functions 5.5Function Definitions 5.6Function Prototypes.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
Random numbers. 2 The Random class A Random object generates pseudo-random numbers. –Class Random is found in the java.util package. import java.util.*;
C++ Programming Lecture 10 Functions – Part II
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
Math 15 Introduction to Scientific Data Analysis Lecture 8 Python Programming – Part 2 University of California, Merced.
Robbie CSCI2100A Data Structures Tutorial
CPSC 441 Tutorial TA: Fang Wang. Simulation Methodology Plan: Introduce basics of simulation modeling Define terminology and methods used Introduce simulation.
CS221 Random Numbers. Random numbers are often very important in programming Suppose you are writing a program to play the game of roulette The numbers.
UFCEKS-20-2Multimedia Authoring Times Table Quiz.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Modular Programming ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
 2000 Prentice Hall, Inc. All rights reserved. 5.2Program Modules in C Functions –Modules in C –Programs combine user-defined functions with library functions.
+ Arrays & Random number generator. + Introduction In addition to arrays and structures, C supports creation and manipulation of the following data structures:
1D Arrays and Random Numbers Artem A. Lenskiy, PhD May 26, 2014.
UNIT 11 Random Numbers.
Chapter 1 t Software Engineering and Computer Programming t Course presentations are available for view and downloading on the course web page: t
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
ONE DIMENSIONAL ARRAYS AND RANDOM NUMBERS. Introduction In addition to arrays and structures, C supports creation and manipulation of the following data.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
CS1010: Programming Methodology
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
MR. CRONE Generating Random Numbers. Random Numbers Many programs require the computer to generate random numbers Random numbers are used in many applications.
Switch Case, Enums, and Random Numbers CS 242 Tarik Booker California State University, Los Angeles.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Functions Course conducted by: Md.Raihan ul Masood
Building Java Programs
Python: Control Structures
CS1010 Programming Methodology
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 6 - Functions Outline 5.1 Introduction
Object Oriented Programming (OOP) LAB # 5
Homework #5 — Monte Carlo Simulation
Applied Discrete Mathematics Week 12: Discrete Probability
Copyright  1997 Oxford University Press All Rights Reserved
Presentation transcript:

Programming Assignment #3 CS-2301, B-Term Programming Assignment #3 User-defined Functions Due, November 18, 11:59 PM (Assignment adapted from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel) Heads up:– Next week, the Programming Assignment will be due on Tuesday, November 24!

Programming Assignment #3 CS-2301, B-Term Objectives Modify someone else’s code Create and use your own functions Read mixed data from input Use enumerated types See handout (.doc,.html)dochtml

Programming Assignment #3 CS-2301, B-Term Approach Download craps.c – a program that “plays” the game of Crapscraps.c Using a random number generator to simulate the rolls of a pair of dice Modify as follows:– Maintain “bank” balance for player Ask player if he/she wants to play another game Accept a wager; test for validity Play the game, update the balance, etc.

Programming Assignment #3 CS-2301, B-Term User-defined Functions Define and implement four functions:– validWager playGame – adapted from existing code adjustBalance getYesOrNo Write pre- and post-conditions for all functions

Programming Assignment #3 CS-2301, B-Term Action of the Game Print current balance If > 0, ask user if he/she wants to play another game Otherwise, print a summary and exit If yes, ask for wager Must be <= balance Play the game Update the balance Repeat

Programming Assignment #3 CS-2301, B-Term Things to Know Mixed numeric and character input See handout Especially for draining lines, dealing with ends of lines Function getchar() More useful than scanf() in many cases

Programming Assignment #3 CS-2301, B-Term Random Number Generators Random numbers are needed frequently in engineering & scientific computations Simulations, arrival times, etc. Exercising other code Analyzing system performance Definition: Random Number Generator A function that returns a seemingly random number each time it is called (Usually) within a specified range Repeated calls yield a random sequence!

Programming Assignment #3 CS-2301, B-Term Random Number Generators (continued) Algorithmic –Retain information in static variables –Scramble numbers to get something that “looks” random on each call Entire mathematical theory about them –Evaluating the quality of the randomness

Programming Assignment #3 CS-2301, B-Term Problem with Random Number Generators Don’t give the same answer each time! Difficult to get reproducible behavior when debugging! Solution:– the seed A numeric value for initializing the internal state So that the generator produces the same sequence each time

Programming Assignment #3 CS-2301, B-Term Linux Random Number Generators There are many! Use rand() Returns values in range rand() % r returns values in range 0.. (r-1) Seeding:– srand(unsigned int seed) –Default 1 srand(time(NULL)) –Seeds to current time (measured in seconds since the beginning) See handout, Appendix B

Programming Assignment #3 CS-2301, B-Term Questions?