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

My previous post expired and wouldnt let me extend the time limit.. I have worke

ID: 3548167 • Letter: M

Question

My previous post expired and wouldnt let me extend the time limit.. I have worked on this for a few hours now and it is working ok. It just doesnt work completely. Here is a short version of what I am working on.                 


                    http://pastebin.com/Pd3ED3NZ                 


                    For some reason the last 'cout's (ie for resistance, tolerance, max and min. are not printing to the screen. Probibly something stupid. Any help would be                    greatly appreciated.

Explanation / Answer

#include <cstdlib> //pre-processor directs - accesses c standard library functions

#include <iostream> //pre-processor directs - iostream talks to screen

#include <iomanip> //pre-processor directs - string

#include <cmath> //pre-processor directs - enables math functions

//***************Res.h file****************************************************

class Resister // class definition

{

private:

double Aband, Bband, Cband, Dband;


public:

Resister (double=0, double=0, double=0, double=0);

int BandA(); //gets user inputs for A color band

int BandB(); //gets user inputs for B color band

int BandC(); //gets user inputs for A, B & C color bands

double BandD(); //gets user input for D color band

double Resistance();

double maxRes();

double minRes();

int bandAA;

int bandBB;

int bandCC;

int bandDD;

};

//****************Res.cpp file*************************************************

//#include <iostream>

//#include <cmath>

//#include "res.h"

//#include <iomanip>

//#include <cstdlib>

//#include <string>

using namespace std;


string StringToLower(string);


Resister::Resister (double A, double B, double C, double D)


{

Aband = A;

Bband = B;

Cband = C;

Dband = D;

}


int Resister::BandA()

{

string bandAS, bandAL;

int bandA;

cin>>bandAS;

bandAL = StringToLower(bandAS);


if (bandAL=="black")

{bandA = 0;}

if (bandAL=="brown")

{bandA = 1;}

if (bandAL=="red")

{bandA = 2;}

if (bandAL=="orange")

{bandA = 3;}

if (bandAL=="yellow")

{bandA = 4;}

if (bandAL=="green")

{bandA = 5;}

if (bandAL=="blue")

{bandA = 6;}

if (bandAL=="violet")

{bandA = 7;}

if (bandAL=="gray")

{bandA = 8;}

if (bandAL=="white")

{bandA = 9;}

if (bandAL=="silver")

{bandA = -1;}

if (bandAL=="gold")

{bandA = -2;}

bandAA = bandA;

return bandA;

}

//*****************Band B******************************************************

int Resister::BandB()

{

string bandBS, bandBL;

int bandB;

cin>>bandBS;

bandBL = StringToLower(bandBS);


if (bandBL=="black")

{bandB = 0;}

if (bandBL=="brown")

{bandB = 1;}

if (bandBL=="red")

{bandB = 2;}

if (bandBL=="orange")

{bandB = 3;}

if (bandBL=="yellow")

{bandB = 4;}

if (bandBL=="green")

{bandB = 5;}

if (bandBL=="blue")

{bandB = 6;}

if (bandBL=="violet")

{bandB = 7;}

if (bandBL=="gray")

{bandB = 8;}

if (bandBL=="white")

{bandB = 9;}

if (bandBL=="silver")

{bandB = -1;}

if (bandBL=="gold")

{bandB = -2;}

bandBB = bandB;

return bandB;

}

//*****************Band C******************************************************

int Resister::BandC()

{

string bandCS, bandCL;

int bandC;

cin>>bandCS;

bandCL = StringToLower(bandCS);


if (bandCL=="black")

{bandC = 0;}

if (bandCL=="brown")

{bandC = 1;}

if (bandCL=="red")

{bandC = 2;}

if (bandCL=="orange")

{bandC = 3;}

if (bandCL=="yellow")

{bandC = 4;}

if (bandCL=="green")

{bandC = 5;}

if (bandCL=="blue")

{bandC = 6;}

if (bandCL=="violet")

{bandC = 7;}

if (bandCL=="gray")

{bandC = 8;}

if (bandCL=="white")

{bandC = 9;}

if (bandCL=="silver")

{bandC = -1;}

if (bandCL=="gold")

{bandC = -2;}

bandCC = bandC;

return bandC;

}

//******************D Band**************************************************

double Resister::BandD() //

{

string bandDS, bandDL;

double bandD;

cin>>bandDS;

bandDL = StringToLower(bandDS);


if (bandDL=="silver")

{bandD = .05;}

if (bandDL=="gold")

{bandD = .10;}

if (bandDL=="none")

{bandD = .20;}

bandDD = bandD;

return bandD;

}

//******************Resistance*************************************************

double Resister::Resistance()

{

double Resistance=(((bandAA*10)+bandBB)*pow(10.0,bandCC));

return Resistance;

}

//****************maximum resistance*******************************************

double Resister::maxRes()

{

double maxRes=Resister::Resistance()+(Resister::Resistance()*bandDD);

return maxRes;

}

//***************minimum resistance********************************************

double Resister::minRes()

{

double minRes=Resister::Resistance()-(Resister::Resistance()*bandDD);

return minRes;

}

//******************string convert*********************************************

string StringToLower(string strToConvert)

{

for (unsigned int i=0;i<strToConvert.length();i++)

{

strToConvert[i] = tolower(strToConvert[i]);

}

return strToConvert;

}


//****************main.cpp file**********************************************

int main()

{

Resister A;


int a, b, c;

double d;

do

{

cout<<" What is the color of the 'A' Band? ";

a=A.BandA();


cout<<" What is the color of the 'B' Band? ";

b=A.BandB();


cout<<" What is the color of the 'C' Band? ";

c=A.BandC();


cout<<" What is the color of the 'D' Band? ";

d=A.BandD();


if ((a<=0)||(b<0)||(d<.05)||(d>.20))

{

cout<<"You have entered an incorrect color"<<endl;

cout<<"These are the colors that you entered in error"<<endl;

if(a<=0) {cout<<"Color band A is incorrect"<<endl;}

if(b<0) {cout<<"Color band B is incorrect"<<endl;}

if((d<.05)||(d>.20)) {cout<<"Color band D is incorrect"<<endl;}


system("pause");

system("cls");

}


cout<<"The resistance is "<<A.Resistance()<<" ohms"<<endl;

cout<<"The tolerance is "<<d<<"%"<<endl;

cout<<"With a maximum resistance value of "<<A.maxRes()<<" ohms"<<endl;

cout<<"and a minimum resistance value of "<<A.minRes()<<" ohms"<<endl;

}

while ((a<=0)||(b<0)||(d<=.05)||(d>=.20));



system("PAUSE");

return EXIT_SUCCESS;

}

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