100 likes | 120 Views
Join Professor Avi Rosenfeld's class for a midterm review session covering topics like rolling dice, histograms, and Craps game plan using C++ programming. Learn about functions, distributions, and enhance your programming skills. No recursion or static data types included.
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