Hi this is my simple c++ programme, it has Thermister class which calculate resistance when varying Temp,but each time when calling to setTemp() eventhough it change value of Temp,value given by getResistance() mthd does not change.It always gives 1 when calling through a for loop.here is the code any help please...
Code:
#include <iostream>
#include <cmath>
class AbstractResistor
{
public:
virtual double getResistance() = 0;
};
class Thermistor:public AbstractResistor
{
private:
double a,b,c,Temp;
public:
Thermistor(double a,double b,double c,double Temp)
{
this->a=a;
this->b=b;
this->c=c;
this->Temp=Temp;
}
~Thermistor(){}
double getResistance()
{
double y=(a-(1/Temp))/c;
double x=sqrt(pow(b/(3*c),3)+pow((y/2),2));
return exp(pow(x-y/2,1/3)-pow(x+y/2,1/3));
}
void setTemp(double Temp)
{
this->Temp=Temp;
}
};
int main()
{
Thermistor* t=new Thermistor(1.4*pow(10,-3),2.37*pow(10,-4),9.9*pow(10,-8),328.15);
std::cout <<"Resistance of Thermistor= "<<t->getResistance();
for(int i=0;i<=100;i++)
{
t->setTemp(i+273.15);
std::cout << t->getResistance()<<std::endl ;
}
return 0;
}
Comment