#include <QString>
#include "complexo.h"
class ComplexData
{
public:
ComplexData();
ComplexData(const ComplexData &);
virtual ~ComplexData();
ComplexData &operator=(const ComplexData & ); // Right side is the argument.
double real;
double imag;
bool FlagNumero;
bool FlagDerivada;
int NivelParentesis;
void SetNumero(double);
//void SetNumero(Complexo);
void SetNumero(double, double);
void SetNumeroVar(double);
bool ValidaFuncao();
bool ValidaNumero();
bool ValidaOperadores();
bool ValidaFuncaoOperador();
bool ValidaParentesis();
bool ValidaConstantes();
bool ValidaConstantesFile(/*QString &*/);
bool ValidaImaginario();
int ValidaOperadorPrioridade();
};
#include <QString>
#include "complexo.h"
class ComplexData
{
public:
ComplexData();
ComplexData(const ComplexData &);
virtual ~ComplexData();
ComplexData &operator=(const ComplexData & ); // Right side is the argument.
QString StrFuncao;
double real;
double imag;
bool FlagNumero;
bool FlagDerivada;
int NivelParentesis;
void SetNumero(double);
//void SetNumero(Complexo);
void SetNumero(double, double);
void SetNumeroVar(double);
void SetFuncao(QString);
bool ValidaFuncao();
bool ValidaNumero();
bool ValidaOperadores();
bool ValidaFuncaoOperador();
bool ValidaParentesis();
bool ValidaConstantes();
bool ValidaConstantesFile(/*QString &*/);
bool ValidaImaginario();
int ValidaOperadorPrioridade();
};
To copy to clipboard, switch view to plain text mode
#include "complexdata.h"
ComplexData::ComplexData()
{
real=0;
imag=0;
StrFuncao="";
FlagNumero=true;
FlagDerivada=false;
NivelParentesis=0;
}
ComplexData::~ComplexData()
{
}
ComplexData &ComplexData::operator=(const ComplexData &dat )
{
FlagNumero=dat.FlagNumero;
FlagDerivada=dat.FlagDerivada;
real=dat.real;
imag=dat.imag;
StrFuncao=dat.StrFuncao;
return *this; // Assignment operator returns left side.
}
ComplexData::ComplexData(const ComplexData &dat)
{
FlagNumero=dat.FlagNumero;
FlagDerivada=dat.FlagDerivada;
real=dat.real;
imag=dat.imag;
StrFuncao=dat.StrFuncao;
// return *this; // Assignment operator returns left side.
}
void ComplexData::SetNumeroVar(double Numero)
{
real=Numero;
imag=0;
FlagNumero=true;
FlagDerivada=true;
StrFuncao.arg(Numero);
}
void ComplexData::SetNumero(double Numero)
{
real=Numero;
imag=0;
FlagNumero=true;
FlagDerivada=false;
StrFuncao.arg(Numero);
}
//void ComplexData::SetNumero(Complexo Numero)
void ComplexData::SetNumero(double r, double i)
{
//real=Numero.r;
//imag=Numero.i;
real=r;
imag=i;
FlagNumero=true;
FlagDerivada=false;
if (real == 0)
{
if (imag == 0)
StrFuncao.arg(real);
if (imag > 0)
StrFuncao.arg(imag);
if (imag < 0)
StrFuncao.arg(-imag);
}
if (real > 0)
{
if (imag == 0)
StrFuncao.arg(real);
if (imag > 0)
StrFuncao.arg(real+imag);
if (imag < 0)
StrFuncao.arg(real-imag);
}
if (real < 0)
{
if (imag == 0)
StrFuncao.arg(-real);
if (imag > 0)
StrFuncao.arg(-real+imag);
if (imag < 0)
StrFuncao.arg(-real-imag);
}
}
void ComplexData
::SetFuncao(QString funcao
) {
real=0;
imag=0;
FlagNumero=false;
FlagDerivada=false;
StrFuncao=funcao;
}
bool ComplexData::ValidaNumero()
{
if (FlagNumero)
return 1;
else
return 0;
}
bool ComplexData::ValidaFuncao()
{
// int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0
if (!StrFuncao.compare("sinc",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("sin",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cos",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("tan",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cotg",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("sinh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cosh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("tanh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cotgh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("asin",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acos",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("atan",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acotg",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("asinh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acosh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("atanh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acotgh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("sqrt",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("log",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("ln",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("exp",Qt::CaseInsensitive))
return 1;
return 0;
}
bool ComplexData::ValidaOperadores()
{
if (StrFuncao == "+")
return 1;
if (StrFuncao == "-")
return 1;
if (StrFuncao == "*")
return 1;
if (StrFuncao == "/")
return 1;
if (StrFuncao == "^")
return 1;
if (StrFuncao == "E")
return 1;
return 0;
}
bool ComplexData::ValidaParentesis()
{
if (StrFuncao == "(")
return 1;
if (StrFuncao == ")")
return 1;
if (StrFuncao == "|")
return 1;
return 0;
}
int ComplexData::ValidaOperadorPrioridade()
{
if (StrFuncao == "+" || StrFuncao == "-" )
return 0;
if (StrFuncao == "*" || StrFuncao == "/" )
return 1;
if (StrFuncao == "^" || StrFuncao == "E" )
return 2;
return -1;
}
bool ComplexData::ValidaFuncaoOperador()
{
if (ValidaFuncao())
return 1;
if (ValidaOperadores())
return 1;
if (ValidaParentesis())
return 1;
return 0;
}
bool ComplexData::ValidaConstantes()
{
if (FlagNumero && !StrFuncao.compare("pi",Qt::CaseInsensitive))
return 1;
if (FlagNumero && !StrFuncao.compare("e",Qt::CaseInsensitive))
return 1;
if (FlagNumero && !StrFuncao.compare("i",Qt::CaseInsensitive))
return 1;
if (FlagNumero && !StrFuncao.compare("j",Qt::CaseInsensitive))
return 1;
return 0;
}
bool ComplexData::ValidaConstantesFile(/*CString &valor*/)
{
FILE *fp_constantes;
// int i;
//Ficheiro de Constantes
if ( fp_constantes = fopen("constantes_file.dat","r") ) //abriu o ficheiro
{
// i=1;
while( fscanf(fp_constantes,"%s",aux_const) != EOF)
{
if (aux_const==StrFuncao)
{
// fscanf(fp_constantes,"%s",valor);
fclose (fp_constantes);
return true;
}
//i++;
}
fclose (fp_constantes);
}
/*else
{
AfxMessageBox("Erro ao abrir o ficheiro das Constantes");
}*/
return false;
}
bool ComplexData::ValidaImaginario()
{
if (FlagNumero && imag != 0)
return 1;
return 0;
}
#include "complexdata.h"
ComplexData::ComplexData()
{
real=0;
imag=0;
StrFuncao="";
FlagNumero=true;
FlagDerivada=false;
NivelParentesis=0;
}
ComplexData::~ComplexData()
{
}
ComplexData &ComplexData::operator=(const ComplexData &dat )
{
FlagNumero=dat.FlagNumero;
FlagDerivada=dat.FlagDerivada;
real=dat.real;
imag=dat.imag;
StrFuncao=dat.StrFuncao;
return *this; // Assignment operator returns left side.
}
ComplexData::ComplexData(const ComplexData &dat)
{
FlagNumero=dat.FlagNumero;
FlagDerivada=dat.FlagDerivada;
real=dat.real;
imag=dat.imag;
StrFuncao=dat.StrFuncao;
// return *this; // Assignment operator returns left side.
}
void ComplexData::SetNumeroVar(double Numero)
{
real=Numero;
imag=0;
FlagNumero=true;
FlagDerivada=true;
StrFuncao.arg(Numero);
}
void ComplexData::SetNumero(double Numero)
{
real=Numero;
imag=0;
FlagNumero=true;
FlagDerivada=false;
StrFuncao.arg(Numero);
}
//void ComplexData::SetNumero(Complexo Numero)
void ComplexData::SetNumero(double r, double i)
{
//real=Numero.r;
//imag=Numero.i;
real=r;
imag=i;
FlagNumero=true;
FlagDerivada=false;
if (real == 0)
{
if (imag == 0)
StrFuncao.arg(real);
if (imag > 0)
StrFuncao.arg(imag);
if (imag < 0)
StrFuncao.arg(-imag);
}
if (real > 0)
{
if (imag == 0)
StrFuncao.arg(real);
if (imag > 0)
StrFuncao.arg(real+imag);
if (imag < 0)
StrFuncao.arg(real-imag);
}
if (real < 0)
{
if (imag == 0)
StrFuncao.arg(-real);
if (imag > 0)
StrFuncao.arg(-real+imag);
if (imag < 0)
StrFuncao.arg(-real-imag);
}
}
void ComplexData::SetFuncao(QString funcao)
{
real=0;
imag=0;
FlagNumero=false;
FlagDerivada=false;
StrFuncao=funcao;
}
bool ComplexData::ValidaNumero()
{
if (FlagNumero)
return 1;
else
return 0;
}
bool ComplexData::ValidaFuncao()
{
// int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0
if (!StrFuncao.compare("sinc",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("sin",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cos",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("tan",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cotg",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("sinh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cosh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("tanh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("cotgh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("asin",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acos",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("atan",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acotg",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("asinh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acosh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("atanh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("acotgh",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("sqrt",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("log",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("ln",Qt::CaseInsensitive))
return 1;
if (!StrFuncao.compare("exp",Qt::CaseInsensitive))
return 1;
return 0;
}
bool ComplexData::ValidaOperadores()
{
if (StrFuncao == "+")
return 1;
if (StrFuncao == "-")
return 1;
if (StrFuncao == "*")
return 1;
if (StrFuncao == "/")
return 1;
if (StrFuncao == "^")
return 1;
if (StrFuncao == "E")
return 1;
return 0;
}
bool ComplexData::ValidaParentesis()
{
if (StrFuncao == "(")
return 1;
if (StrFuncao == ")")
return 1;
if (StrFuncao == "|")
return 1;
return 0;
}
int ComplexData::ValidaOperadorPrioridade()
{
if (StrFuncao == "+" || StrFuncao == "-" )
return 0;
if (StrFuncao == "*" || StrFuncao == "/" )
return 1;
if (StrFuncao == "^" || StrFuncao == "E" )
return 2;
return -1;
}
bool ComplexData::ValidaFuncaoOperador()
{
if (ValidaFuncao())
return 1;
if (ValidaOperadores())
return 1;
if (ValidaParentesis())
return 1;
return 0;
}
bool ComplexData::ValidaConstantes()
{
if (FlagNumero && !StrFuncao.compare("pi",Qt::CaseInsensitive))
return 1;
if (FlagNumero && !StrFuncao.compare("e",Qt::CaseInsensitive))
return 1;
if (FlagNumero && !StrFuncao.compare("i",Qt::CaseInsensitive))
return 1;
if (FlagNumero && !StrFuncao.compare("j",Qt::CaseInsensitive))
return 1;
return 0;
}
bool ComplexData::ValidaConstantesFile(/*CString &valor*/)
{
FILE *fp_constantes;
QString aux_const;
// int i;
//Ficheiro de Constantes
if ( fp_constantes = fopen("constantes_file.dat","r") ) //abriu o ficheiro
{
// i=1;
while( fscanf(fp_constantes,"%s",aux_const) != EOF)
{
if (aux_const==StrFuncao)
{
// fscanf(fp_constantes,"%s",valor);
fclose (fp_constantes);
return true;
}
//i++;
}
fclose (fp_constantes);
}
/*else
{
AfxMessageBox("Erro ao abrir o ficheiro das Constantes");
}*/
return false;
}
bool ComplexData::ValidaImaginario()
{
if (FlagNumero && imag != 0)
return 1;
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks