Part i ex 1 is worth 1200 points part1ex 2 is worth 800 poin



Part i, ex 1 is worth 1200 points, part1ex 2 is worth 800 points, part2 ex 1 is worth 800 points and part 2 ex 2 is worth 1200 points for total of 4000 points. FCP Part LCC programming 1.l write a c program that will determine the resistance value (in ohms o kohms) of a carbon or metal fim resistor ranglng from 1/8 to s wattsl when the program user inputs the three colors of the resistor\'s color band. Your program should accept the followirecharacters as string variable inputs for the three resistor color bands: BLACK \'B\' (o for bands one or two and powr10.0 for band three) BROWN- b 1 for bands one or two and pow(10,1) for band three RED \'R\' or \'r (2 for bands ane or two and powl10,2) for band three) ORANGE \'o\' or \'o\' (3 for bands one or two and powt10.3l tor band three) YELLOW or Y (4 for bands one or two and powflDA for band three)

Solution

#include <stdio.h>



void getColorCode(char colorCode[]);

long getResistorValue( char colorCode[], int colorValue[], int r_value );

//void getResistorValue(char colorCode[], int colorValue[]);



int main (void)

{

long r_value = 0; //should be long to store large values

char colorCode[4];

int colorValue[4];

// int i;



printf(\"This program will calculate the value of a resistor.\ \ \");

printf(\"B = Black\ b = Brown\ R or r= Red\ O or o = Orange\ Y or y = Yellow\ \");

printf(\"G = Green\ U or u = Blue\ V or v = Violet\ g = Gray\ W or w = White\ \ \");

printf(\"Enter the 4-character color description of the resistor: \");



getColorCode(colorCode);



//for (i = 0; i < 4; i++)

//function returns a long , should be stored in a long variable

r_value = getResistorValue(colorCode, colorValue, r_value);



printf(\"\ \ The resistor with color code %c %c %c %c has a value of %d Ohms.\ \",

colorCode[0], colorCode[1], colorCode[2], colorCode[3], r_value);



return 0;

}



void getColorCode(char colorCode[])

{

int i;

for(i = 0; i < 4; i++)

colorCode[i] = getchar();

}



long getResistorValue( char colorCode[], int colorValue[], int r_value )

{



int i;

int j;

long multiplier;



for( i = 0; i < 3; i++)

{

switch (colorCode[i])

{



case(\'B\'):

colorValue[i] = 0;

break;



   case(\'b\'):

colorValue[i] = 1;

break;



case(\'r\'):

case(\'R\'):

colorValue[i] = 2;

break;



case(\'o\'):

case(\'O\'):

colorValue[i] = 3;

break;



case(\'y\'):

case(\'Y\'):

colorValue[i] = 4;

break;





case(\'G\'):

colorValue[i] = 5;

break;



case(\'U\'):

case(\'u\'):

colorValue[i] = 6;

break;



case(\'v\'):

case(\'V\'):

colorValue[i] = 7;

break;


case(\'g\'):

colorValue[i] = 8;

break;



case(\'w\'):

case(\'W\'):

colorValue[i] = 9;

break;

default: break;

}

}



for( j = 0; j < 8; j++)

{

switch (colorCode[3])

{


case(\'B\'):

multiplier = 1;

break;

   case(\'b\'):

multiplier = 10;

break;
  

case(\'r\'):

case(\'R\'):

multiplier = 100;

break;

case(\'o\'):

case(\'O\'):

multiplier = 1000;

break;

case(\'y\'):

case(\'Y\'):

multiplier = 10000;

break;

case(\'G\'):


multiplier = 100000;

break;

case(\'U\'):

case(\'u\'):

multiplier = 1000000;

break;

case(\'v\'):

case(\'V\'):

multiplier = 10000000;

break;

//case w not implemented

default: break;

}

r_value = ((colorValue[0] + (colorValue[1]) + (colorValue[2])) * multiplier);

}

return r_value;

}

 Part i, ex 1 is worth 1200 points, part1ex 2 is worth 800 points, part2 ex 1 is worth 800 points and part 2 ex 2 is worth 1200 points for total of 4000 points.
 Part i, ex 1 is worth 1200 points, part1ex 2 is worth 800 points, part2 ex 1 is worth 800 points and part 2 ex 2 is worth 1200 points for total of 4000 points.
 Part i, ex 1 is worth 1200 points, part1ex 2 is worth 800 points, part2 ex 1 is worth 800 points and part 2 ex 2 is worth 1200 points for total of 4000 points.
 Part i, ex 1 is worth 1200 points, part1ex 2 is worth 800 points, part2 ex 1 is worth 800 points and part 2 ex 2 is worth 1200 points for total of 4000 points.
 Part i, ex 1 is worth 1200 points, part1ex 2 is worth 800 points, part2 ex 1 is worth 800 points and part 2 ex 2 is worth 1200 points for total of 4000 points.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site