#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Resistance
{
private:
double resistance;
int tolerance;
string BandA;
string BandB;
string BandC;
string BandD;
public:
int Find_Resistance(string,string,string,string,double&,int&);
int Find_Bands(double,int);
void Find_RMaxMin(double&,double&);
}
int Resistance::Find_Resistance(string band1, string band2, string band3, string band4, double &res, int &tol)
{
BandA = band1;
BandB = band2;
BandC = band3;
BandD = band4;
if ( BandB == "black" ) resistance = 0;
else if ( BandB == "brown" ) resistance = 1;
else if ( BandB == "red" ) resistance = 2;
else if ( BandB == "orange" ) resistance = 3;
else if ( BandB == "yellow" ) resistance = 4;
else if ( BandB == "green" ) resistance = 5;
else if ( BandB == "blue" ) resistance = 6;
else if ( BandB == "violet" ) resistance = 7;
else if ( BandB == "gray" ) resistance = 8;
else if ( BandB == "white" ) resistance = 9;
else return 2;
if ( BandA == "black" );
else if ( BandA == "brown" ) resistance += 10;
else if ( BandA == "red" ) resistance += 20;
else if ( BandA == "orange" ) resistance += 30;
else if ( BandA == "yellow" ) resistance += 40;
else if ( BandA == "green" ) resistance += 50;
else if ( BandA == "blue" ) resistance += 60;
else if ( BandA == "violet" ) resistance += 70;
else if ( BandA == "gray" ) resistance += 80;
else if ( BandA == "white" ) resistance += 90;
else return 1;
if ( BandC == "black" );
else if ( BandC == "brown" ) resistance *= 1E1;
else if ( BandC == "red" ) resistance *= 1E2;
else if ( BandC == "orange" ) resistance *= 1E3;
else if ( BandC == "yellow" ) resistance *= 1E4;
else if ( BandC == "green" ) resistance *= 1E5;
else if ( BandC == "blue" ) resistance *= 1E6;
else if ( BandC == "violet" ) resistance *= 1E7;
else if ( BandC == "gray" ) resistance *= 1E8;
else if ( BandC == "white" ) resistance *= 1E9;
else if ( BandC == "silver" ) resistance *= 1E-1;
else if ( BandC == "gold" ) resistance *= 1E-2;
if ( BandD == "gold" ) tolerance = 5;
else if ( BandD == "silver" ) tolerance = 10;
else if ( BandD == "none" ) tolerance = 20;
else return 3;
res = resistance;
tol = tolerance;
return 0;
}
int Resistance::Find_Bands(double res, int tol)
{
if ( res >= 100000000 || res <= 0.01 ) return 1;
if ( tol != 5 || tol != 10 || tol != 20 ) return 2;
}
void Resistance::Find_RMaxMin(double &min, double &max)
{
min = resistance - resistance * tolerance / 100.0;
max = resistance + resistance * tolerance / 100.0;
}
void decapitalize(string &in)
{
stringstream stream;
char temp;
int length;
length = in.length();
stream << in;
in.clear();
for ( int i = 0; i < length; i++ )
{
stream >> temp;
if ( temp < 97 ) temp += 32;
in += temp;
}
}
int main()
{
double r;
int t;
double RMax;
double RMin;
string band1,band2,band3,band4;
int option;
Resistance resistor;
cout << "Enter the first color band: ";
cin >> band1;
cout << "Enter the second color band: ";
cin >> band2;
cout << "Enter the third color band: ";
cin >> band3;
cout << "Enter the forth color band: ";
cin >> band4;
decapitalize(band1);
decapitalize(band2);
decapitalize(band3);
decapitalize(band4);
resistor.Find_Resistance(band1,band2,band3,band4,r,t);
cout << "Resistance: " << r << endl;
cout << "Tolerance: " << t << endl;
}
The error log:N:\EGR125summer10\Project2\Project2.cpp|21|error: new types may not be defined in a return type| N:\EGR125summer10\Project2\Project2.cpp|21|error: extraneous `int' ignored| N:\EGR125summer10\Project2\Project2.cpp|21|error: prototype for `Resistance Resistance::Find_Resistance(std::string, std::string, std::string, std::string, double&, int&)' does not match any in class `Resistance'| N:\EGR125summer10\Project2\Project2.cpp|16|error: candidate is: int Resistance::Find_Resistance(std::string, std::string, std::string, std::string, double&, int&)| N:\EGR125summer10\Project2\Project2.cpp|21|error: `Resistance Resistance::Find_Resistance(std::string, std::string, std::string, std::string, double&, int&)' and `int Resistance::Find_Resistance(std::string, std::string, std::string, std::string, double&, int&)' cannot be overloaded| N:\EGR125summer10\Project2\Project2.cpp||In member function `Resistance Resistance::Find_Resistance(std::string, std::string, std::string, std::string, double&, int&)':| N:\EGR125summer10\Project2\Project2.cpp|36|error: conversion from `int' to non-scalar type `Resistance' requested| N:\EGR125summer10\Project2\Project2.cpp|47|error: conversion from `int' to non-scalar type `Resistance' requested| N:\EGR125summer10\Project2\Project2.cpp|63|error: conversion from `int' to non-scalar type `Resistance' requested| N:\EGR125summer10\Project2\Project2.cpp|66|error: conversion from `int' to non-scalar type `Resistance' requested| ||=== Build finished: 9 errors, 0 warnings ===|It looks to me that the compiler thinks I declared Find_Resistance as Resistance class, when I actually declared it as an int.
BTW, I know my coding isn't the best, like using int return types to return errors, but I'm just following directions, so please don't suggest improvements to error checking, etc.


Sign In
Create Account


Back to top









