Question
Below I have attached my output. The top part of the picture is what the program should do, the bottom part of the picture is
Below I have attached my output. The top part of the picture is what the program should do, the bottom part of the picture is what my program is currently doing. I want to use the sum of band1 and band2 to set to the closest standard EIA value which are already set in arrays. My program correctly identifies the correct colors to make that resistance value however it isn't correctly finding the closest Standard resistance value. Once I find that I can reuse the resistance to color function again to show the correct band colors. This is all done through c++.
using namespace std; //introduces namespace std //EIA Standard array element sizes per tolerance class const int E12 = 12; // 10% tolerance const int E24 = 24; // 5% tolerance const int E6 = 6; // 20% tolerance
const int nominalE12values[E12]={10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82}; // 10% tolerance const int nominalE24values[E24]={10,11,12, 13, 15, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 43, 47, 51, 56, 62, 68, 75, 82, 91} ; // 5% tolerance const int nominalE6values[E6]={10, 15, 22, 33, 47, 68}; // 20% tolerance
class Resistance { private: double resValuee; int tolValueee; string cband1,cband2,cband3,cband4;
public: int colorToResistancee(string,string,string,string,double&,int&); //member functions
intStandardRes(string&,string&,string&,string&,double&,int&); int ResistanceToColor(double,int, string &, string &, string &, string &); void maxminResistancee(double&,double&);
*rr (double) and Tt (int) have been declared .
int main()
else if(answer=="b")
{
cout> rr; cout> tt; resistor.ResistanceToColor(rr,tt,bA,bB,bC,bD); resistor.StandardRes(bA,bB,bC,bD,rr,tt); cout
int Resistance::StandardRes(string &b1 ,string &b2, string &b3, string &b4, double &resR, int &tolR) { cband1 = b1; cband2 = b2; cband3 = b3; cband4 = b4; if ( cband2 == "black" ) resValuee = 0; if ( cband2 == "brown" ) resValuee = 1; if ( cband2 == "red" ) resValuee = 2; if ( cband2 == "orange" ) resValuee = 3; if ( cband2 == "yellow" ) resValuee = 4; if ( cband2 == "green" ) resValuee = 5; if ( cband2 == "blue" ) resValuee = 6; if ( cband2 == "violet" ) resValuee = 7; if ( cband2 == "gray" ) resValuee = 8; if ( cband2 == "white" ) resValuee = 9; else return 2; if ( cband1 == "black" ); if ( cband1 == "brown" ) resValuee += 10; if ( cband1 == "red" ) resValuee += 20; if ( cband1 == "orange" ) resValuee += 30; if ( cband1 == "yellow" ) resValuee += 40; if ( cband1 == "green" ) resValuee += 50; if ( cband1 == "blue" ) resValuee += 60; if ( cband1 == "violet" ) resValuee += 70; if ( cband1 == "gray" ) resValuee += 80; if ( cband1 == "white" ) resValuee += 90; else return 1; if ( cband4 == "gold" ) { tolValueee = 5; for(int i=1 ; inominalE24values[i-1] && resValuee
int Resistance::ResistanceToColor(double resIn, int tolIn,string& b1, string &b2, string &b3, string &b4)
{
if ( resIn >= 100000000 || resIn
int multiplierCnt=0;
int t;
t=log10(resIn/10.f);
int t1=resIn/pow(double(10),t+1);
int t2=int(resIn/pow(double(10),t))%10;
int t3=t;
if(t1==0)
b1="black";
else if(t1==1)
b1="brown";
else if(t1==2)
b1="red";
else if(t1==3)
b1="Orange";
else if(t1==4)
b1="Yellow";
else if(t1==5)
b1="Green";
else if(t1==6)
b1="Blue";
else if(t1==7)
b1="Violet";
else if(t1==8)
b1="Gray";
else
b1="White";
if(t2==0)
b2="black";
else if(t2==1)
b2="brown";
else if(t2==2)
b2="red";
else if(t2==3)
b2="Orange";
else if(t2==4)
b2="Yellow";
else if(t2==5)
b2="Green";
else if(t2==6)
b2="Blue";
else if(t2==7)
b2="Violet";
else if(t2==8)
b2="Gray";
else
b2="White";
if(t3==0)
b3="black";
else if(t3==1)
b3="brown";
else if(t3==2)
b3="red";
else if(t3==3)
b3="Orange";
else if(t3==4)
b3="Yellow";
else if(t3==5)
b3="Green";
else if(t3==6)
b3="Blue";
else if(t3==7)
b3="Violet";
else if(t3==8)
b3="Gray";
else
b3="White";
if(tolIn20)
return 0;
if(tolIn==5)
b4="gold";
else if(tolIn==10)
b4="silver";
else if(tolIn==20)
b4="NONE";
}
Step 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