Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please show the codesthank you Resistors are painted with coloured bands that can be decoded to determine their resistance value. In this lab, you will

Please show the codesthank you image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Resistors are painted with coloured bands that can be decoded to determine their resistance value. In this lab, you will be decoding the resistance of 4-band resistors. Figure 1 contains a chart, which is a mapping from the colour of each band to a numerical value. When these 4 values are combined, one can arrive at a resistance value and a tolerance for that resistor. 4-Band-Code 560k + 5% CHAR COLOR 1ST BAND 2ND BAND MULTIPLIER TOLERANCE + 1% RA 2 K. Black Bb Brown Red 0. Orange Yellow G. Green Uu Blue V.V Violet YY Grey Ww White LL Gold Silver oo NOSI + 2% 10 100 1000 1KO 10KO 100K 1MO 10MO 5 5 6 7 7 88 99 +0.5% +0.25% + 0.10% +0.05% 0.10 0.019 + 5% 10% Figure 1: 4-Band Resistor Colour Code Chart Given the example in the chart (the colour bands Green, Blue, Yellow, and Gold), the calculation is performed as follows. The first two bands are combined to create a 2-digit number, in this case 56 (Green 5 and Blue 6). This value is then multiplied by the value corresponding to the third color, in this case 10 kN (Yellow), leaving us with a resistance value of 560 k. Next, since resistors are not perfect, we want to know the uncertainty in the resistance value, which is also known as the tolerance. The fourth and final band contains this value. Finally, after looking up the colour gold in the tolerance column, we arrive at a value of 560 kN + 5%. Resistance Calculator Program Write a program, Lab3.c, that starts by prompting the user for the four colour codes of two resis- tors. The four colour codes of the first resistor will be asked sequentially, followed by the four colour codes of the second resistor. Each colour will be entered by the user as a single character, either cap- ital or lower case, according to the first column of the chart in Figure 1. Your program will then print out the full names of the four colour bands for each resistor, the cor- responding resistance value for each resistor, and the equivalent resistance if they are associated in series and in parallel. The format that you will use must follow the examples given below, in terms of the line spacing and wording. If the user enters a letter that does NOT correspond to a valid colour code, your program should catch that and present an error message, as indicated in Example 3 below. When the first error is caught, at whatever band or resistor, the program exits displaying the correct values up to that point followed by the error message. The series equivalent resistance is calculated by the sum of the two resistors. The parallel equivalent is calculated by the ratio between their product and their sum (product over sum). Sample Outputs Example 1: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Green Blue Yellow Gold Colour bands for resistor 2: Green Blue Yellow Gold Value in ohms of resistor 1: 560.00 KOhms +/- 5.00% Value in ohms of resistor 2: 560.00 KOhms +/- 5.00% The Equivalent in series is 1.12 MOhms The Equivalent in parallel is 280.00 Kohms Example 2: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Black White Brown Grey Colour bands for resistor 2: Brown Black Red Gold Value in ohms of resistor 1: 90.00 Ohms +/- 0.05% Value in ohms of resistor 2: 1.00 KOhms +/- 5.00% The Equivalent in series is 1.09 KOhms The Equivalent in parallel is 82.57 Ohms Example 3: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Brown Black Orange Silver Colour bands for resistor 2: Invalid colour for the 1st band of resistor 2. Exiting the program... For example 3, note that capital letters and lower case letters were used as inputs, which are valid inputs. Note also that the letter z is not a valid input, and was entered for the 1st band of the sec- ond resistor. The program exited at that point displaying an error message. Example 3: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: O Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Brown Black Red Green Colour bands for resistor 2: Brown Brown Orange Invalid colour for the tolerance band of resistor 2. Exiting the program... For the example above, the user input a wrong tolerance band (probably thinking "p" for "pink"). The program outputs an error message and exits. Resistors are painted with coloured bands that can be decoded to determine their resistance value. In this lab, you will be decoding the resistance of 4-band resistors. Figure 1 contains a chart, which is a mapping from the colour of each band to a numerical value. When these 4 values are combined, one can arrive at a resistance value and a tolerance for that resistor. 4-Band-Code 560k + 5% CHAR COLOR 'T BAND 2N0 BAND MULTIPLIER ISO- TOLERANCE + 1% 2% RA O 2 3 4 3 102 100 1000 1KO 10KO 100K 1MO 10MO 5 Black Bb Brown Red Orange Yellow Green U. Blue V, v Violet YAY Grey Ww White LL Gold Silver 5 6 7 8 9 N + 0.5% +0.25% + 0.10% +0.05% 7 8 0.10 0.010 + 5% 10% T Figure 1: 4-Band Resistor Colour Code Chart Given the example in the chart the colour bands Green, Blue, Yellow, and Gold), the calculation is performed as follows. The first two bands are combined to create a 2-digit number, in this case 56 (Green = 5 and Blue = 6). This value is then multiplied by the value corresponding to the third color, in this case 10 kN (Yellow), leaving us with a resistance value of 560 k 2. Next, since resistors are not perfect, we want to know the uncertainty in the resistance value, which is also known as the tolerance. The fourth and final band contains this value. Finally, after looking up the colour gold in the tolerance column, we arrive at a value of 560 kN2 + 5%. Resistance Calculator Program Write a program, Lab3.c, that starts by prompting the user for the four colour codes of two resis- tors. The four colour codes of the first resistor will be asked sequentially, followed by the four colour codes of the second resistor. Each colour will be entered by the user as a single character, either cap- ital or lower case, according to the first column of the chart in Figure 1. Your program will then print out the full names of the four colour bands for each resistor, the cor- responding resistance value for each resistor, and the equivalent resistance if they are associated in series and in parallel. The format that you will use must follow the examples given below, in terms of the line spacing and wording. If the user enters a letter that does NOT correspond to a valid colour code, your program should catch that and present an error message, as indicated in Example 3 below. When the first error is caught, at whatever band or resistor, the program exits displaying the correct values up to that point followed by the error message. The series equivalent resistance is calculated by the sum of the two resistors. The parallel equivalent is calculated by the ratio between their product and their sum (product over sum). Sample Outputs Example 1: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Green Blue Yellow Gold Colour bands for resistor 2: Green Blue Yellow Gold Value in ohms of resistor 1: 560.00 KOhms +/- 5.00% Value in ohms of resistor 2: 560.00 KOhms +/- 5.00% The Equivalent in series is 1.12 MOhms The Equivalent in parallel is 280.00 Kohms Example 2: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Black White Brown Grey Colour bands for resistor 2: Brown Black Red Gold Value in ohms of resistor 1: 90.00 Ohms +/- 0.05% Value in ohms of resistor 2: 1.00 KOhms +/- 5.00% The Equivalent in series is 1.09 KOhms The Equivalent in parallel is 82.57 Ohms Example 3: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Brown Black Orange Silver Colour bands for resistor 2: Invalid colour for the 1st band of resistor 2. Exiting the program... For example 3, note that capital letters and lower case letters were used as inputs, which are valid inputs. Note also that the letter z is not a valid input, and was entered for the 1st band of the sec- ond resistor. The program exited at that point displaying an error message. Example 3: Please enter the 1st band of resistor 1: Please enter the 2nd band of resistor 1: Please enter the multiplier band of resistor 1: Please enter the tolerance band of resistor 1: Please enter the 1st band of resistor 2: Please enter the 2nd band of resistor 2: Please enter the multiplier band of resistor 2: Please enter the tolerance band of resistor 2: Colour bands for resistor 1: Brown Black Red Green Colour bands for resistor 2: Brown Brown Orange Invalid colour for the tolerance band of resistor 2. Exiting the program... For the example above, the user input a wrong tolerance band (probably thinking "p" for "pink"). The program outputs an error message and exits

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions