ECE 1021

HOMEWORK #3

(Last Modified: 27 Nov 2010 )

PROGRAM A - Resistor Color Code

Programming Problem #5.4 (p224).

MODIFICATION: Write the function so that it takes two arguments:

void color_band(double r, int tol);

r is the resistance and tol is the tolerance.

Based on the tolerance, your program must decide whether to use three, four, or five color bands.

Note: The allowed tolerances are 20%, 10%, 5%, 2%, and 1%.

PROGRAM B - The Monty Hall Problem

Programming Problem #5.20 (p226).

MODIFICATION: User controlled "Verbosity Level"

Write your program so that the user can decide how game-by-game results are to be displayed. Have them indicate this as a "Verbosity Level" as follows:

Level 0 - Don't print out anything during the simulation loop - only before and after the entire simulation is run.

Level 1 - For each game, print out whether the user won or lost.

Level 2 - For each game, print out Level 1 + whether the player stayed or switched (useful for Strategy 2).

Level 3 - Level 1 & 2 info plus cumulative totals (games played, games switched and won, games stayed and won).

Level 4 - Level 1, 2, & 3 info plus cumulative statistics (% won when switched, %won when stayed).

You should find the above easy to implement and very useful in your debugging.

To be turned in with source code:

Run simulations using each of the above verbosity levels and report how many simulations per minute you can perform at each level. To get that value, you might want to write some "wrapper code" that calls the rest of your program in a loop (with a different verbosity level on each pass) and uses the timer functions (in time.h) to measure how long it took to execute the simulation. An alternative is to simply run a large enough simulations that it takes at least a few minutes to perform them and sit there with a watch and time how long it takes.

The results might surprise you.

Hints on Program A

Resistor Color Code (HW#3) explained in more detail

A color-coded resistor as either three, four, or five color bands on it.

Three Band resistors

Four Band resistors

Five Band resistors

A site that you might find helpful is http://www.geocities.com/regor_ph/index.html .

A word of warning about the above site is in order. The main purpose is to give you a site that lets you see what these "color codes" are and this site does that pretty nicely. Unfortunately, this site doesn't care whether the information you provided would actually result in a legitimate code so it will allow you to specify a five-band resistor with 10% tolerance - something that is not allowed because a value that is only known to 10% does not have three significant digits. 

Use the information provided above to determine, based on the entered tolerance, how many color bands to output. Also, keep in mind that you need to perform rounding in order to get the correct answer. For instance, if the person enters a resistance of 16666 ohms with a tolerance of 5%, you know that you need to print out the bands that correspond to 1-7-3-5%.