Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C-language question Computing resistance of one resistor from its color bands. A resistor is a small electronic component, and it comes with three (of four)

C-language question

Computing resistance of one resistor from its color bands.

A resistor is a small electronic component, and it comes with three (of four) colored stripes on it. See

http://en.wikipedia.org/wiki/Electronic_color_code

We won't be concerned with the tolerance, so we will just need to know about bands A, B, and C. Each color refers to a one digit number - here I will call them codeA, codeB, and codeC. The resistance for the resistor is then computed as

(10 * codeA + codeB) * 10codeC

Write the following functions:

void showColors();

We need letters to represent colors. displayColors should display the following table:

Black B

Brown N

Red R

Orange O

Yellow Y

Green G

Blue E

Violet V

Gray g

White W

(These are the only colors we will be dealing with.)

int digit(char color);

Given a letter representing a color on a resistor, this will return the corresponding one digit code. As in the table above, color can be any of the letters B,N,R,O,Y,G,E,V,g,W. Use the table at http://en.wikipedia.org/wiki/Electronic_color_code to get the corresponding code values.

For example, a yellow stripe will be represented by Y and the corresponding one digit code is 4. So digit('Y') will return the value 4.

long long computeCode(char colorA, char colorB,

char colorC);

Given a resistor with letters colorA, colorB, colorC representing the three color stripes, it will return the resistance of a resistor.

For example, computeCode('R','g', 'N');

will determine that the code for 'R' is 2, the code for 'g' is 8, and the code for 'N' is 1 (using computeCode three times).

It will then compute

(2*10 + 8)*101

=280

and return the value 280. (This is the resistance in ohms.)

Since the numbers can get larger than a standard int can hold, we will use type long long, which stands for long long int. (At least 64 bits.) (For testing: the format string for printing a long long is %lld.)

Each of the functions should have a comment above the function header in the function definition, briefly describing what the function does.

Write a main that displays the table of letters representing colors. It then asks the user how many resistors they have. It then repeatedly asks for a user to enter the codes for the three color stripes of resistors, reads in that information in the form XYZ (no spaces), and prints the corresponding resistance in ohms. The program should terminate when the given number of resistors have been entered.

Sample output:

Black B

Brown N

Red R

Orange O

Yellow Y

Green G

Blue E

Violet V

Gray g

White W

How many resistors are there? 4

Enter 3 colors in form XYZ: WWW

resistor: 99000000000 ohms.

Enter 3 colors in form XYZ: RgN

resistor: 280 ohms.

Enter 3 colors in form XYZ: BBB

resistor: 0 ohms.

Enter 3 colors in form XYZ: OgR

resistor: 3800 ohms.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago