Question
Here is my code that I need help solving. Mainly at void getColorBands(char*, char*, char*,char*) and void calcResistance(char, char, char, char). #include #include #include void
Here is my code that I need help solving. Mainly at void getColorBands(char*, char*, char*,char*) and void calcResistance(char, char, char, char).
#include
void prompt(void); //Function provided void calcResistorColors(int); //Function Provided void getColorBands(char*, char*, char*,char*); //Function Provided void calcResistance(char, char, char, char); //Function Provided
int main() { int ch=1; int code; do { prompt(); //Call the prompt function that will display resistors code printf("Please enter the value of resistor: "); scanf("%d",&code); if (code>0 && code
calcResistorColors(code); printf("Would like to try another resistor ? Please enter 1 if yes: "); scanf("%d",&ch); } else printf("Enter invalid code Please enter valid code from the given below "); } while(ch==1); }
void prompt(void) { printf("--------------------Resistor Codes--------------------- "); printf("|Character| Color | Band 1 & 2 | Band 3 | Band 4 | "); printf("| K | Black | 0 |*1 |+/- 1%% | "); printf("| N | Brown | 1 |*10 |+/- 2%% | "); printf("| R | Red | 2 |*100 | | "); printf("| O | Orange | 3 |*1,000 | | "); printf("| Y | Yellow | 4 |*10,000 | | "); printf("| G | Green | 5 |*100,000 |+/- 0.5%% | "); printf("| B | Blue | 6 |*1,000,000 |+/- 0.25%%| "); printf("| V | Violet | 7 |*10,000,000|+/- 0.1%% | "); printf("| E | Grey | 8 | |+/- 0.05%%| "); printf("| W | White | 9 | | | "); printf("| D | Gold | | |+/- 5%% | "); printf("| S | Silver | | |+/- 10%% | "); printf("------------------------------------------------------- ");
}
void calcResistorColors(int code) //this function gives the color combination of the given code of resistor { int band1,band2,band3=0; int c,t1,t2,t3; char color[][20] = {"Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Grey","White","Gold","Silver"};
c=log10(code);
t1=pow(10,c);
t2=pow(10,c-1);
band1=code/t1;
band2=(code/t2)-band1*10;
if(code>99)
band3=code-(band1*t1)-(band2-1)*t2;
t3=log10(band3);
printf("%s-%s-%s",color[band1],color[band2],color[t3]);
printf(" indicate to %d-%d-%d ",band1,band2,band3); } void getColorBands(char*, char*, char*,char*) { } void calcResistance(char, char, char, char) {
}
4-Band Code 2%, 5%, 10% 4k 72 5% Color 1' Rand und and Multiplier Tolerance O 2 3 th 12 4 4 TO 6 7 6 7 IMO 10MO 3 IN 010 SP 5-Band Code 63k4 0.1% 0.1%, 0.25% 0.5%, 1% Figure 1: Resistor Color Code Update your Lab-1-Part-1 tool to now be one main looping program with two resistor identification functions: one for determining the color-code of a given resistor value, and one to provide the resistor value when given a color-code. 1. Open Code-Blocks and start a new console application project Copy in the contents from Lab 1 Part 1 to use as a starting point. 2. Add the following function prototypes to the top of your file in addition to Lab l's prototypes: a. void getColorBands(char*, char*, char*, char*); b. void calcResistance(char,char,char, char); 3. The source code for each of your functions should be written below your main function. Optionally, if you would like to get more practice with libraries (Part 2), you could create a Resistance Library. 4. Update the prompt(void) function: a. This function should display the Color-Code Scheme displayed in Table 1 them ask the user if they would like to convert a color-code to a resistance value or determine the color-code from a resistance value. NOTE Table 1 has two more rows and one more column than in Lab 1. To save you time, the print statements for Table 1 have been provided to you in Appendix-4 1. Description of getColorBands (char*, char*, char*, char*) function: 2. This function is to be designed to collect user input of 4 characters, aligning with the character-to- color scheme shown in Table 1. b. Instead of returning anything, this function takes 4 pointers to characters as parameters. Obtaining these characters by reference means this function can "Tetun" all 4 values of user input in one function call. Make sure to error check that the user did not input an invalid color-character. 2. Description of calcResistance (char,char,char,char) function: 2. This function should take, as parameters, 4 characters that describe the color-code of a resistor. Based on these colors, the function should determine the value of the resistor and print that to the screen b. HINT: Consider using a switch-case statement in your decryption Table 1: Resistor Color-Cods Character Scheme Character 3 Band 1"& 2 Band 0 4 Band -- 100 - 2% N R O Color Black Brown Red Orange Yellow 10 -100 1,000 *10,000 100,000 * 1,000,000 10,000,000 Green 2 3 4 5 6 7 8 9 +/- 0.5% -- 0.25% +-0.1% -0.05% B V E W D S Blue Violet Grey White Gold Silver -0.01 +-5% +/- 10% 3. Description of getResistor Colors. (int) function: 2. This function should take as a parameter, an integer value of a resistor. For the sake of simplicity, we will ignore the tolerance (4 band) and fractional multipliers of Gold and Silver in the 3 band in this step, so the integer should only be between 1-99M ohms. Make sure to error check this before proceeding. Assuming a valid integer, determine what the 3-band colors would be for this integer, using a leading-0 as necessary b. HINT: Consider making a getIntBetween function that sets a min and maximum value to retrieve values between and returns a valid integer. CHINT: Consider determining what multiplier is being used before determining what digits are present in the first two bands. You can accomplish this by counting the number of times the number can be divided by 10 before it itself is less than 100 (a two-digit number). 4. Your main function should do the following: a Call the prompt function to request user input on decryption technique. b. Collect user input for which method of conversion desired Perform the requested task d. Ask the user if they would like to try another resistor i. If yes, loop back to step A 4-Band Code 2%, 5%, 10% 4k 72 5% Color 1' Rand und and Multiplier Tolerance O 2 3 th 12 4 4 TO 6 7 6 7 IMO 10MO 3 IN 010 SP 5-Band Code 63k4 0.1% 0.1%, 0.25% 0.5%, 1% Figure 1: Resistor Color Code Update your Lab-1-Part-1 tool to now be one main looping program with two resistor identification functions: one for determining the color-code of a given resistor value, and one to provide the resistor value when given a color-code. 1. Open Code-Blocks and start a new console application project Copy in the contents from Lab 1 Part 1 to use as a starting point. 2. Add the following function prototypes to the top of your file in addition to Lab l's prototypes: a. void getColorBands(char*, char*, char*, char*); b. void calcResistance(char,char,char, char); 3. The source code for each of your functions should be written below your main function. Optionally, if you would like to get more practice with libraries (Part 2), you could create a Resistance Library. 4. Update the prompt(void) function: a. This function should display the Color-Code Scheme displayed in Table 1 them ask the user if they would like to convert a color-code to a resistance value or determine the color-code from a resistance value. NOTE Table 1 has two more rows and one more column than in Lab 1. To save you time, the print statements for Table 1 have been provided to you in Appendix-4 1. Description of getColorBands (char*, char*, char*, char*) function: 2. This function is to be designed to collect user input of 4 characters, aligning with the character-to- color scheme shown in Table 1. b. Instead of returning anything, this function takes 4 pointers to characters as parameters. Obtaining these characters by reference means this function can "Tetun" all 4 values of user input in one function call. Make sure to error check that the user did not input an invalid color-character. 2. Description of calcResistance (char,char,char,char) function: 2. This function should take, as parameters, 4 characters that describe the color-code of a resistor. Based on these colors, the function should determine the value of the resistor and print that to the screen b. HINT: Consider using a switch-case statement in your decryption Table 1: Resistor Color-Cods Character Scheme Character 3 Band 1"& 2 Band 0 4 Band -- 100 - 2% N R O Color Black Brown Red Orange Yellow 10 -100 1,000 *10,000 100,000 * 1,000,000 10,000,000 Green 2 3 4 5 6 7 8 9 +/- 0.5% -- 0.25% +-0.1% -0.05% B V E W D S Blue Violet Grey White Gold Silver -0.01 +-5% +/- 10% 3. Description of getResistor Colors. (int) function: 2. This function should take as a parameter, an integer value of a resistor. For the sake of simplicity, we will ignore the tolerance (4 band) and fractional multipliers of Gold and Silver in the 3 band in this step, so the integer should only be between 1-99M ohms. Make sure to error check this before proceeding. Assuming a valid integer, determine what the 3-band colors would be for this integer, using a leading-0 as necessary b. HINT: Consider making a getIntBetween function that sets a min and maximum value to retrieve values between and returns a valid integer. CHINT: Consider determining what multiplier is being used before determining what digits are present in the first two bands. You can accomplish this by counting the number of times the number can be divided by 10 before it itself is less than 100 (a two-digit number). 4. Your main function should do the following: a Call the prompt function to request user input on decryption technique. b. Collect user input for which method of conversion desired Perform the requested task d. Ask the user if they would like to try another resistor i. If yes, loop back to step AStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started