Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code from lab 1! Please add comments/ explanation of thought process I wanna understand the code! Thank you! void prompt (void); //function

image text in transcribedimage text in transcribedThis is the code from lab 1!image text in transcribedimage text in transcribedimage text in transcribed

Please add comments/ explanation of thought process I wanna understand the code! Thank you!

void prompt (void); //function prototype void calcResistorColors (int); //function prototype int main() { int ch=l; int i; do { prompt(); //call prompt function that displays resistors code scanf("%d",&i);//scans in input for i if (i>0 && i99) band3=resist- (bandl*tl) - (band2-1)*t2;// calculates multiplier t3=log10 (band3); printf("$3-$3-$s", color[bandl], color[band2], color[t3]);//prints the colors of the bands from color array printf(" indicate to $d-$d-%d ", band, band2, band3);// breaks down the number into each band 1 Part I Resistor Analysis Tool Pt. 2 In Lab 1, you created a resistor analysis tool that would take a resistance value and output the color-code for that resistor. In Lab-2, you are to update this analysis tool to allow the user the choice between entering resistance or a color-code, outputting the conversion in either direction. Reference Figure 1 again for the color-code used for 4-band and 5-band resistors, though we will again only be utilizing a 4-band approach. 4-Band Code 2%, 5%, 10% JUL 4k 702 +5% Tolerance 1" Band 0 1 20 Band 0 1 2 3 3 Band 0 1 2 3 +1% 2 3 Multiplier 10 100 1000 1k 10ko 100k 1 10 MO 4 4 Color Black Brown Red Orange Yellow Green Blue Violet Grey White Gold Silver 4 5 5 6 6 5 6 7 8 9 +0.5% +0.25% +0.1% + 0.05% 7 8 7 8 9 9 9 0.10 0.0102 +5% +10% ITA 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 ls 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 then 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-A 1. Description of getColor Bands (char*, char*, char*, char*) function: a. 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 return 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: a. 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-Code Character Scheme 4th Band +/- 1% +/- 2% Character K N R O Y G B V E W D S Color Black Brown Red Orange Yellow Green Blue Violet Grey White Gold Silver 1st & 2nd Band 0 1 2 3 4 5 6 7 8 9 3rd Band *1 *10 *100 *1,000 *10,000 *100,000 *1,000,000 *10,000,000 +/- 0.5% +/- 0.25% +/-0.1% +/- 0.05% *0.1 *0.01 +/- 5% +/- 10% 3. Description of getResistor Colors (int) function (this is a repeat from Lab 1): a. This function should take, as a parameter, an integer value of a resistor. For the sake of simplicity, we will ignore the tolerance (4th band) and fractional multipliers of Gold and Silver in the 3rd 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. C. HINT: 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 c. Perform the requested task d. Ask the user if they would like to try another resistor i. If yes, loop back to step A ii. If no, exit the program 5. Error Checking: All points of user input should be carefully error checked to ensure there is no chance for invalid, malicious input. For example, if the program is expecting an integer between 1-999, entering a negative number or a number too large should fail and ask them to try again. Likewise, entering a character when an integer is expected should not break the program. void prompt (void); //function prototype void calcResistorColors (int); //function prototype int main() { int ch=l; int i; do { prompt(); //call prompt function that displays resistors code scanf("%d",&i);//scans in input for i if (i>0 && i99) band3=resist- (bandl*tl) - (band2-1)*t2;// calculates multiplier t3=log10 (band3); printf("$3-$3-$s", color[bandl], color[band2], color[t3]);//prints the colors of the bands from color array printf(" indicate to $d-$d-%d ", band, band2, band3);// breaks down the number into each band 1 Part I Resistor Analysis Tool Pt. 2 In Lab 1, you created a resistor analysis tool that would take a resistance value and output the color-code for that resistor. In Lab-2, you are to update this analysis tool to allow the user the choice between entering resistance or a color-code, outputting the conversion in either direction. Reference Figure 1 again for the color-code used for 4-band and 5-band resistors, though we will again only be utilizing a 4-band approach. 4-Band Code 2%, 5%, 10% JUL 4k 702 +5% Tolerance 1" Band 0 1 20 Band 0 1 2 3 3 Band 0 1 2 3 +1% 2 3 Multiplier 10 100 1000 1k 10ko 100k 1 10 MO 4 4 Color Black Brown Red Orange Yellow Green Blue Violet Grey White Gold Silver 4 5 5 6 6 5 6 7 8 9 +0.5% +0.25% +0.1% + 0.05% 7 8 7 8 9 9 9 0.10 0.0102 +5% +10% ITA 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 ls 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 then 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-A 1. Description of getColor Bands (char*, char*, char*, char*) function: a. 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 return 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: a. 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-Code Character Scheme 4th Band +/- 1% +/- 2% Character K N R O Y G B V E W D S Color Black Brown Red Orange Yellow Green Blue Violet Grey White Gold Silver 1st & 2nd Band 0 1 2 3 4 5 6 7 8 9 3rd Band *1 *10 *100 *1,000 *10,000 *100,000 *1,000,000 *10,000,000 +/- 0.5% +/- 0.25% +/-0.1% +/- 0.05% *0.1 *0.01 +/- 5% +/- 10% 3. Description of getResistor Colors (int) function (this is a repeat from Lab 1): a. This function should take, as a parameter, an integer value of a resistor. For the sake of simplicity, we will ignore the tolerance (4th band) and fractional multipliers of Gold and Silver in the 3rd 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. C. HINT: 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 c. Perform the requested task d. Ask the user if they would like to try another resistor i. If yes, loop back to step A ii. If no, exit the program 5. Error Checking: All points of user input should be carefully error checked to ensure there is no chance for invalid, malicious input. For example, if the program is expecting an integer between 1-999, entering a negative number or a number too large should fail and ask them to try again. Likewise, entering a character when an integer is expected should not break the program

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

More Books

Students also viewed these Databases questions

Question

Identify the elements that make up the employee reward package.

Answered: 1 week ago

Question

Understand the purpose, value and drawbacks of the interview.

Answered: 1 week ago