//========================================================================= #define PROGRAMMER "SOLUTIONS, NoFrills" #define PROG_CODE "soln" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "HW #3A" #define REVISION (0) #define TITLE "Resistor Color Code" #define SUBTITLE "Problem 5.4" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "03a0soln.txt" //========================================================================= // PROBLEM: // // Write a function that prints the color codes for a resistor given the // resistance and the tolerance. // // SOLUTION: // // As given in the auxillary information on the course website, the codes // fall into three types - 3 band, 4 band, and 5 band - based on the // tolerance. // // Tolerance = 20% => 3 Band (Value, Value, Multiplier) // Tolerance = 10% => 4 Band (Value, Value, Multiplier, Silver) // Tolerance = 5% => 4 Band (Value, Value, Multiplier, Gold) // Tolerance = 2% => 5 Band (Value, Value, Value, Multiplier, Red) // Tolerance = 1% => 5 Band (Value, Value, Value, Multiplier, Brown) // // No other tolerances are valid. // // We know that the multiplier has to be between 0.01 and 1e9. If the // resistance value not less than than 100 (1000 for 5-band resistors) // then we can divide by ten and up the multiplier. If, upon reaching // a multiplier of 1e9 the value is still not less than 100 (or 1000) // we know the value can't be represented. // // On the other end, if the value is less than 10 (100 for 5-band) then // we cam multiply by ten until it is, subject to the constraint that // we can only do this twice. If the value at that time is less than one. // the value can't be represented. // // Once we have the resistance scaled properly, we can then round the // value to the nearest integer and use modulo ten division to pick off // the ones, tens, and (for 5-band) the hundreds digits in turn. // // PSEUDOCODE // // 1) TASK: Get valid tolerance from user. // 2) TASK: Get resistance value from user. // 3) TASK: Determine the number of color bands. // 4) TASK: Scale the resistance value properly and determine multiplier // 5) TASK: Round the scaled resistance to the nearest integer. // 6) TASK: Determine the digit values for the value bands. // 7) TASK: Print out the band colors for the resistor. //