Week 6 - Consolidation, Random Numbers, and Recursion
This is a week of consolidation, in which we
cover Chapter 6 (Modular Programming) and Chapter 7 (Simple Data
Types) of Friedman and Koffman. We also introduce Random Numbers
(mainly associated with lab 6) and Recursive Functions.
The various relevant programs for this week
have been loaded onto condor. After logging in, change directory to the week6 directory
and list the various files as follows:
cd /home/condor/et181/week6
ls
- Section 6.1: Value and Reference Parameters
computeSumAve.cpp - computing the sum and average of two numbers, introducing
Call-by-Value and Call-by-Reference parameters
(p 294)
void computeSumAve(float,
float, float&, float&);
- Section 6.2: Functions with Output and Input
Parameters
testGetFrac.cpp - reads a fraction typed in by a user and returns
the numerator and denominator (p 304)
swap.cpp - swapping the values of 2 float variables (swap.pdf overheads)
- Section 6.4: Using Objects with Functions
testMoneyToNumber.cpp
- removing the $ sign and , from a
money string (p 322)
- A paradigm for the for loop usage
in our third programming exercise
sin.cpp - for loop - two columns of n coordinate points [x, sin(x)]
- introducing <iomanip>
- epsilon.cpp - <cfloat>
the smallest (FLT_EPSILON) and largest (FLT_MAX) float values
rightri.cpp - determine
if 3 sides form a right-angled triangle within a defined error
margin (epsilon) - NEVER compare floats for equality!
try_pie.cpp - test a rational
fraction approximation for pi (The first millon digits of p)
- Section 6.6: Recursive Functions (in directory
recursion)
chatter.cpp - an infinite
recursive loop - simulating a typical meeting between two good
folk at the steps of the Old Court House in Athens, Ohio.
n_chatter.cpp - a "n"
limited recursive loop
re_bottles.cpp - 99 bottles
of beer using a recursive function
re_fact.cpp - factorial
table using a recursive function
- random10.cpp - Introducing
random numbers
- Lab 6: lab_area -
the area under a sine curve using
a Monte Carlo (random) method
