Mar 23, 2019 at 10:24am UTC
Hello, it must be a nonsense but i can not see it
I hace two files Proincipal.cpp with the main and other Individuo which code is:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Individuo{
public:
Individuo(string str1, string str2): factor{str1}, operacion{str2}
{ cout << "Initialised with " << factor[0] << " and " << operacion[0] << '\n'; }
string getFactor(int j)
{
return factor[j];
}
void setFactor(string ftr)
{
factor.push_back(ftr);
}
string getOperacion(int i)
{
return operacion[i];
}
void setOperacion(string op)
{
operacion.push_back(op);
cout<<"En metodo set operacion:"<<op<<endl;
}
void setFormula(int j, int i)
{
formula = getFactor(j) + getOperacion(i) + formulaN;
cout<<"formula...en Individuo.= "<<formula<<" j="<<j<<" i="<<i<<endl;
cout<<"Individuo...getFactor(j)="<<getFactor(j)<<endl;
cout<<"Individuo...getOperacion(i)="<<getOperacion(i)<<" "<<operacion[i]<<endl;
formula=formulaN;
}
void setFormulaN()
{
formulaN=formula;
}
private:
string formulaN="",formula="";
vector<string> factor;
vector<string> operacion;
};
The problem is that getOperacion don't return anything on the contrary that getFactor...but they are symetric...they work the same
what i'm doing wrong?
thanks
Mar 23, 2019 at 10:41am UTC
Are you sure 0 ≤ i < operacion.size() ?
Mar 23, 2019 at 10:48am UTC
the main clase contain:
while(n<20){
n++;
cout << "Principal n<20... "<<n<<endl;
ind.setFormulaN();
for (int j=0;j<=4;j++)
{
if(j==0){factor="r";}
else if(j==1){factor="M";}
else if(j==2){factor="teta";}
else if(j==3){factor="1";}
else if(j==4){factor="2";}
for (int i=0;i<=5;i++)
{
cout << "bucle for i en main·.."<<endl;
if(i==0){operacion="+";}
else if(i==1){operacion="-";}
else if(i==2){operacion="*";}
else if(i==3){operacion="/";}
else if(i==4){operacion="^";}
else if(i==5){operacion="sin";}
cout<<"en main for n>0:"<<n<<"operacion:"<<operacion<<endl;
ind.setFactor(factor);
ind.setOperacion(operacion);
ind.setFormula(j,i);
}
}
}
and I can see the content of string operacion
Mar 23, 2019 at 10:54am UTC
the methos set works properly