Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Background: A resister is an electronic circuit device designed to have a specif

ID: 3761184 • Letter: B

Question

Background:

A resister is an electronic circuit device designed to have a specific resistance value between its ends.

Resistance values are expressed in ohms ( ), kilo-ohms ( k ), or megaohms ( m ).

Resistors are marked using a color-coding that signifies their resistance values.

We will focus on the inexpensive resistors (see the diagram on the next page) which have three bands on the left side. The first two bands represent digits, between 0 and 9, and the third band is a power-of-ten multiplier. Thus, if the first band is blue and the second is grey, using the table below, we see that is 68. Brown says to multiply that value by 10, resulting in a final value of 680. If there is no tolerance band, which in this example is blank and therefore isn’t specified, the default tolerance is 20%. Also, if the cell in the tolerance column is blank, as it is for orange, yellow, and white, it is also classified as a default tolerance.

You can see a web-based program that does this (which you can use to confirm your program is working correctly) at http://resistor.cherryjourney.pt

Program Requirements: Write an interactive program to prompt the user to enter the colors of bands 1 through 4 of a resistor. Allow the user to enter in the colors using words that are either upper or lower case, and use functions provided by the header to work around this input (check out strncasecmp for an amazingly easy way to do it).

Here's a sample of how the program might work:

Enter the colors of the resistor’s three bands, staring with the one on the left.

Band 1: green

Band 2: black

Band 3: yellow

Band 4: blank

Resistance value: 500 kilo-ohms.

Tolerance: 20%, or 400 kilo-ohms to 600 kilo-ohms variance

Do you want to decode another resister? Y

Band 1: BLUE

Band 2: Grey

Band 3: brown

Band 4: Green

Resistance value: 680 ohms.

Tolerance: 0.5%, or 676.6 ohms to 683.4 ohms variance.

Do you want to decode another resister? N

Use the following global constant for comparing your color codes:

const char COLOR_CODES[10] [7] = { "black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white" };

Use C programming to create the source code.

Explanation / Answer

#include #include #include #include int search (char codes[10][7], char target[], int size); int main (void) { char COLOR_CODES [10][7] = {"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "gray", "white"}; float Resistance_value; char band1[7]; char band2[7]; char band3[7]; int i,j,k; char question; printf("This program is designed to calculate the resistance value between the ends of a resistor."); printf(" Do you want to decode resistor now (Type 'y' for yes, or 'n' for no)? "); printf(" => "); scanf("%c", &question); while (question == 'y') { printf(" Enter the colors of the resistor's three bands, beginning with the band nearest the end. "); printf("Type the colors in lowercase letters only, NO CAPS. "); printf ("Band 1 => "); scanf("%s",&band1); printf ("Band 2 => "); scanf("%s",&band2); printf ("Band 3 => "); scanf("%s",&band3); i = search (COLOR_CODES, band1, 10); j = search (COLOR_CODES, band2, 10); k = search (COLOR_CODES, band3, 10); Resistance_value = (10*i+j)*(pow(10,k)); if (i == -1 || i == 0) { printf ("Invalid colors : %s", i); } if (j == -1 ) { printf ("Invalid colors : %s", j); } if (k == -1 ) { printf ("Invalid colors : %s", k); } else { printf ("Resistance value: %.0f ohms ", Resistance_value); } scanf("%c", &question); printf(" Do you want to decode another resistor (Type 'y' for yes, or 'n' for no)? "); printf(" => "); scanf("%c", &question); } system("pause"); return 0; } int search (char codes[][7], char target[], int size) { int x = 0; int match = 0; int location; while (!match && x
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote