Resistor Values Develop a PROLOG program
Electrical Engineering Case Study - Resistor Values
Develop a PROLOG program that prompts the user for the colors of Band 1, Band 2, Band 3, and Band 4 and then displays the resistance in Kilo-ohms.
A resistor is a circuit device designed to have a specific resistance value between its ends (see http://en.wikipedia.org/wiki/Resistors for more details on resistors). Resistance values are expressed in ohms (Ω) or kilo-ohms (k Ω). Resistors are frequently marked with four colored bands that encode their resistance values, as shown below. The first two bands encode the first two significant digits of the resistance value, the third is a power-of-ten multiplier or number-of-zeroes, and the fourth is the tolerance accuracy, or acceptable error, of the value.
(Source: http://ikalogic.com/beg_1_res_v_c.php)
The table below shows the meanings of each band color. For example, if the first band is green, the second is black, and third is orange, and the fourth is silver, the resistor has a value of 50 X 103 ± 0.1X50X103 Ω or 50 ± 5 kΩ.
Color | 1st band | 2nd band | 3rd band (multiplier) | 4th band (tolerance) |
Black | 0 | 0 | ×100 | |
Brown | 1 | 1 | ×101 | |
Red | 2 | 2 | ×102 | |
Orange | 3 | 3 | ×103 | |
Yellow | 4 | 4 | ×104 | |
Green | 5 | 5 | ×105 | |
Blue | 6 | 6 | ×106 | |
Violet | 7 | 7 | ×107 | |
Gray | 8 | 8 | ×108 | |
White | 9 | 9 | ×109 | |
Gold | ×10-1 | ±5% | ||
Silver | ×10-2 | ±10% |
The Challenge:
Develop a PROLOG program that prompts the user for the colors of Band 1, Band 2, Band 3, and Band 4 and then displays the resistance in Kilo-ohms. Assume that band 4 can only be Gold or Silver.
a) Present a main menu to the user about the following options:
a) Calculate resistance value
b) Help
c) Exit
The “help” option presents some information about the program and how to use it, and re-displays the main menu options. The “Exit” option terminates the program. The “Calculate resistance value” leads the user to a secondary menu as shown in Step 2.
b) The secondary menu prompts the user to select the band colors. For example:
a) Black
b) Brown
c) Red
d) Orange
e) Yellow
f) Green
.
.
Please select the color for band 1: 5
Please select the color for band 2: 0
Please select the color for band 3: 3
Please select the color for band 4: 11
The resistance value is: 50 ± 5 kΩ
Then the program should print back the main menu (Step 1).
c) If the user enters an invalid value, print an error message, and prompt the user for another value.
Here is a snapshot of what the program will look like:
10 years ago
Purchase the answer to view it
- resistor_values_develop_a_prolog_program_1.doc
- resistor_values_develop_a_prolog_program_2.doc