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

Array please help resistor is a circuit device designed to have a specific resis

ID: 3634766 • Letter: A

Question

Array
please help

resistor is a circuit device designed to have a specific resistance value between its ends. Resistance values are expressed in ohms or kilo-ohms. Resistors are frequently marked with colored bands that encode their resistance values:

We’re going to ignore the tolerance for this example, dealing only with the first two bands, which are digits, and the third, which is a power-of-ten multiplier. The following table shows the meanings of each band color.

Color Value as Digit Value as Multiplier
Black 0 100 (1)
Brown 1 101 (10)
Red 2 102 (100)
Orange 3 103
Yellow 4 104
Green 5 105
Blue 6 106
Violet 7 107
Gray 8 108
White 9 109

For example, if the first band is green, the second is black, and the third is orange, the resistor has a value of 50 x 103 ohms, or 50 kilo-ohms.
One can store the color codes in a C++ program using an array of strings:
Color Codes [0] black
[1] brown
… …
[9] white
Notice that in this case, the index-value for each element is equal to the color’s value as digit or multiplier (pretty cool!).

Your Task: will be to write a program that creates the array of strings shown as colorCodes, then outputs something similar to the table of colors, values as digits and values as multipliers. After that, the program prompts for the colors Band 1, Band 2, and Band 3 and displays the resistancein kilo-ohms (NOT ohms). On the last page of this handout is a sample run from my “key” program. Probably easiest would be to mimic this (considering time constraints).

You will need a GLOBAL const for the size of the array (10) and a local-to-main array of strings for the color codes. #include <string> is essential for the program to work! Include the following functions (the rest of the processing can be done within main() if you like):

• Void getCodes (string[]) is a void function that prompts for, reads in and stores 10 colors in the color code array. Since there are always exactly 10 color codes, you don’t need to keep track of how many strings are actually read and stored.

• Void outputCodeTable (string[]) outputs the table. I found that using tab stops made it fairly easy to have the values line up. Here was my heading cose for the first two lines:

cout << “ Color Value as Digit Value as Multiplier ”;
cout << “----- -------------- ------------------- ”;

• Int linearSearch(const string[], int, string) is taken almost exactly from the liner search algorithm / code we showed in class Wednesday…except you are looking for a string instead of an int key.

To Hand In:
Your code
Printout of running the program with the following resistor values:
Green, black, yellow
Brown vilet gray (which should be seen as having an error caused when linear search foes not find ‘vilet’ in the color code array)
Yellow violet red
3 colors of your choice
HINT: Since the program is more about arrays than anything else, I’ll give you the pseudocode expressions I used to calculate the resistance. Given that digit1 is the index/number for Band 1, digit2 the index/number for Band 2, and power the multiplier:

resistance = digit1 * 10 + digit2;
power = pow(10.0, power);
resistance = resistance * power;
cout << “Resistance value: “ << resistance / 1000 << “ kilo-ohms ”;









Enter 10 color codes. This can be on one line or one-per-line.
Black brown red orange yellow green blue violet gray white


Color Value as Digit Value as Multiplier
----- -------------- -------------------
black 0 10 to the 0 power
brown 1 10 to the 1 power
red 2 10 to the 2 power
orange 3 10 to the 3 power
yellow 4 10 to the 4 power
green 5 10 to the 5 power
blue 6 10 to the 6 power
violet 7 10 to the 7 power
gray 8 10 to the 8 power
white 9 10 to the 9 power

Enter the colors of the resistor’s three bands, beginning with the band nearest the end. Type the colors in lowercase letters only: NO CAPS.
Band 1 => green
Band 2 => black
Band 3 => yellow
Resistance value: 500 kilo-ohms
Do you want to decode another resistor?
=> y

Enter the colors of the resistor’s three bands, beginning with the band nearest the end. Type the colors in lowercase letters only: NO CAPS.
Band 1 => brown
Band 2 => vilet
Band 3 => gray
Invalid color: vilet
Do you want to decode another resistor?
=> n


Explanation / Answer

#include #include using namespace std; int search( const string* array, unsigned size, string target ) { // add your code here } int main() { const string first_try[1] = {"black"}; int result = search( first_try, 1, "foo" ); assert( result == -1 ); cout
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