0

Hi,

I created a member file name "ConverterA" but it keep saying has no member. Please help me in this situation. What does it mean?

class Resistance
{
      private:
                string ColorA[9], ColorB[10], ColorC[12], ColorD[12]; 
                int Resistances, Tolerance;

      public:
                int SelectedOP2();
                int Option();                
                int ConverterA(string);
                int ConverterB(string); 
                int ConverterD(string);
                int Converter(string);
                string ConverterD(int);

};
// assuming that everything is declared and defined

int main()
{ 
     colorA = A.ConverterA(Color[0]); // from here to "ConverterD" it keeps saying "no member named"
     colorB = A.ConverterB(Color[1]);
     colorC = A.Converter(Color[2]);
     colorD = A.ConverterD(Color[3]);
}

Thank you in advance

3
Contributors
8
Replies
11
Views
6 Years
Discussion Span
Last Post by Akill10
0

Can you post the exact command line you're using to compile along with compiler errors exactly as reported?

0

This is one of the member i'm trying to compile

int Resistance::ConverterB(string color)
{
 return ConverterD(color); // function definition
}

the error, same as the others says :
'struct std::string' has no member named 'ConverterB'

if you need the whole program i can post it as well but i warn you its pretty long. hehe.

0

I have change couple lines to fit the project's requirements but basically its the same problem.

#include <iostream>
#include <string>
#include <fstream>   
#include <sstream>      
#include <cmath>   

using namespace std;
//------------------Function Prototype---------------------
                int ConverterA(string);
                int ConverterB(string); 
                int ConverterD(string);
                int Converter(string);
                string ConverterD(int);
//------------------Class----------------------------------                
class Resistance
{
      private:
                string ColorA[9], ColorB[10], ColorC[12], ColorD[12]; 
                int Resistances, Tolerance;

      public:

                int Option();
                int Rmax(int, int);
                int Rmin(int, int);
                int TolConv(string);
                int R(int, int);

};
     
int Resistance::Rmax(int resist, int tol)
{
 resist = resist*(tol/100.0)+resist;
 return resist;
}
int Resistance::Rmin(int resist, int tol)
{
 resist = resist-resist*(tol/100.0);
 return resist;
}

int Resistance::TolConv(string color)
{
 return ConverterD(color);
}

int Resistance::R(int resist, int color)
{
 resist = resist*pow(10.0,color);
 return resist;
}

int Resistance:: Option ()
{
    int option;
    
    cout << "Please Choose From The Fallowing Option : " << endl;
    cout << "\t1 - Convert color of bands to ohms\n\t2 - Convert ohm to color of bands" << endl;
    cout << "Enter Option Number : " ;
    cin  >> option; 
    cout << endl << endl ; 
    return option;
    
}
///////////////////////////////////MAIN////////////////////////////
int main ()
{ 
    int option;
    Resistance A;
 
    option = A.Option();

     if (option == 1)
     {
     int colorA, colorB, colorC, colorD; 
     double Rsistance,;
     string Color[4], answer;
     char temp1[10], temp2[10];
     do
    {       
string answer = "n";
string A, B, C, D;

cout << "Please enter a color for band A: ";
cin  >> A;

                 for (int i=0; i< A.length(); i++) 
                 {
                     A[i]=tolower(A[i]);
                 }
             Color[0] = A;
             cout << "Please enter a color for band B: ";
             cin  >> B;

             
                 for (int j=0; j<B.length(); j++) 
                 {
                     B[j]=tolower(B[j]);
                 }
             Color[1] = B;             
             cout << "Please enter a color for band C: ";
             cin  >> C;      
                      
                 for (int k=0; k<C.length(); k++) 
                 {
                     C[k]=tolower(C[k]);
                 }
             Color[2] = C;             
             cout << "Please enter a color for band D: ";
             cin  >> D;                           
                  for (int l=0; l<C.length(); l++) 
                 {
                     D[l]=tolower(D[l]);
                 }
             Color[3] = D;   
     
     colorA = ConverterA(Color[0]);
     colorB = ConverterB(Color[1]);
     colorC = Converter(Color[2]);
     colorD = A.TolConv(D);  // this causes error. only reported one error.
     

 /////////////////////Check System////////////////////////////////////    

                      
            if(colorA == 10 )
            {cout << "\nError! Invalid input in Color band A" << endl;
            cout << "\nWould you like to try again? Enter Y: " ;
            cin >> answer; 
            cout << endl; }

            else if(colorB == 10 )
            {cout << "\nError! Invalid input in Color band B" << endl;
            cout << "\nWould you like to try again? Enter Y: " ;
            cin >> answer;
            cout << endl; }
            
            else if(colorC == 10 )
            {cout << "\nError! Invalid input in Color band C" << endl;
            cout << "\nWould you like to try again? Enter Y: " ;
            cin >> answer;
            cout << endl;} 
            
            else if(colorD == 0 )
            {cout << "\nError! Invalid input in Color band D" << endl;
            cout << "\nWould you like to try again? Enter Y: " ;
            cin >> answer;
            cout << endl; }
            
            else
                answer = "n";
     }
          
     while (answer == "y" || answer == "Y");
  ////////////////////////////Converts Interger to Character//////////////////////
    itoa (colorA,temp1,16);
    itoa (colorB,temp2,16);

strcat(temp1, temp2);

int result;
stringstream convert(temp1);
if(!(convert >> result))
result = 0;

cout << "\nR = " << A.R(result,colorC) << " ohms" << endl;
cout << "Tolerance = " << colorD << "%" << endl;
cout << "Rmax = " << A.Rmax(result,colorD)<< " ohms" << endl;
cout << "Rmin = " << A.Rmin(result,colorD)<< " ohms" << endl << endl;
/////////////////////////////////////////////////////////////////////////////

}
     
     if (option != 1 && option != 2)
     cout << "Error! Invalid input option" << endl;
     
     system("pause");
     return 0;
     
}
////////////////////////Function Definition//////////////////////////////////
//----------------------------For Bands-----------------
int Converter (string Color)
{
    if (Color == "black")
    return 0;
    if (Color == "brown")
    return 1;    
    if (Color == "red")
    return 2;
    if (Color == "orange")
    return 3;
    if (Color == "yellow")
    return 4;
    if (Color == "green")
    return 5;
    if (Color == "blue")
    return 6;
    if (Color == "violet")
    return 7;
    if (Color == "gray")
    return 8;
    if (Color == "white")
    return 9;
    if (Color == "silver")
    return -1;
    if (Color == "gold")
    return -2;
    else
        return 10;
}
//----------------------------For Band D-----------------
int ConverterD (string D)
{
    if (D == "gold")
    return 5;

    if (D == "silver")
    return 10;
    
    if (D == "none")
    return 20;
    
    else
    return 0;
}
//----------------------------For Band D-----------------
string ConverterD (int D)
{
    if (D == 5)
    return "gold";

    if (D == 10)
    return "sivler";
    
    if (D == 20)
    return "none";
    
    else
    return 0;
}
//----------------------------For Band A-----------------
int ConverterA( string Color)
{
if (Color == "brown")
    return 1;    
    if (Color == "red")
    return 2;
    if (Color == "orange")
    return 3;
    if (Color == "yellow")
    return 4;
    if (Color == "green")
    return 5;
    if (Color == "blue")
    return 6;
    if (Color == "violet")
    return 7;
    if (Color == "gray")
    return 8;
    if (Color == "white")
    return 9;
    else
    return 10;
}
//----------------------------For Band B-----------------
int ConverterB( string Color)
{
    if (Color == "black")
    return 0;
    if (Color == "brown")
    return 1;    
    if (Color == "red")
    return 2;
    if (Color == "orange")
    return 3;
    if (Color == "yellow")
    return 4;
    if (Color == "green")
    return 5;
    if (Color == "blue")
    return 6;
    if (Color == "violet")
    return 7;
    if (Color == "gray")
    return 8;
    if (Color == "white")
    return 9;
    else
    return 10;
}

Thank you for helping me

0
[B]Resistance A;[/B]//HERE YOU DECLARE A VARIABLE A

	option = A.Option();

	if (option == 1)
	{
		int colorA, colorB, colorC, colorD; 
		double Rsistance;
		string Color[4], answer;
		char temp1[10], temp2[10];
		do
		{       
			string answer = "n";
			[B]string A[/B], B, C, D;//HERE YOU DECLARE A AGAIN

Your Resistance object goes out of scope, therefore, you are trying to find a TolConv function in std::string.

Also, your variable names are terrible, if you actually thought about what the variable will do/how it will be used when naming it, it will be much easier to avoid these kind of problems

Edited by Akill10: n/a

0

oh I see. wow that worked. thanks a lot. i'll rename it to a different variable.

1

Increase warning level. Compiler would tell you of such conflicts..

Even so, it's not the compilers fault, such conflicts shoudln't really occur anyway :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.