100 likes | 207 Views
In Class 19 of the Introduction to Computers and Programming course, Professor Avi Rosenfeld reviews key concepts for Midterm #2 and introduces Homework #5. Important topics covered include the rolling of dice, histogram creation for roll distributions, and the game's rules for Craps. Participants will review functions for rolling one and two dice, as well as the use of random number generation in C++. This session also provides resources and links to example programs to further enhance understanding of the material discussed.
E N D
Introduction to Computers and Programming Class 19 Review for Midterm #2 Professor Avi Rosenfeld
Admin To do List • Introduce HW #5 • No Recursion or static data types • Questions about the exam?
Phone phun http://www.cs.nyu.edu/courses/fall01/V22.0002-001/programs/class19/cpp1.c
Game Plan – Rolling the “dice” • Roll one die. • Roll two dice. • Find Doubles. • Histograms of rolls. • Craps (7, 11) (2,3) or same
Rolling One Die #include <time.h> #include <stdlib.h> int Roll1 () { return 1 + rand() % 6; }
Rolling Two Dice int Roll2 () { return Roll1() + Roll1(); }
Histogram Function (stars) void Hist(int x) { printf("The Histograph of %d is:n", x); for (int i = 0; i < x; i++) printf("*"); printf("\n"); }
Using the functionsDistribution of one Die http://www.cs.nyu.edu/courses/fall01/V22.0002-001/programs/class19/cpp2.c
Using the functionsDistribution of two Dice http://www.cs.nyu.edu/courses/fall01/V22.0002-001/programs/class19/cpp3.c
Craps http://www.cs.nyu.edu/courses/fall01/V22.0002-001/programs/class19/craps.c