How would you go about reading in a math function that has coefficients,exponents, and trig into a node from a file?
Example input line from file: 3x^4 + 2tan 10x
I can't figure out a way to create a variable that would be able to identify what the trig function is if there is one present. I thought about maybe comparing a c-string of the file to a character pointer array that has all of the trig functions initialized. Any advice would be appreciated. Thank you!
I wrote a node class to store the coefficients and exponents in, but making a variable to identify the trig component of the input is where i'm having trouble.
class Node {
private:
int outerCoefficient;
int innerCoefficient;
int exponent;
char trigIdentifier[5];
const char* trigFunctions[12] =
{
"sin", "cos", "tan", "cot", "sec", "csc", "asin", "acos",
"atan", "acot", "asec", "acsc"
};
Node* next;
public:
Node();
Node(int outCf, int inCf, int exponent);
int getOuterCoefficient();
int getInnerCoefficient();
int getExponent();
void setOuterCoefficient(int val);
void setInnerCoefficient(int val);
void setExponent(int val);
char* getTrigFunction(char*);
friend ostream& operator << (ostream& output, const Node& Node);
};
In the function where you are reading from a file you coul dhave a char * variable that stores 3 or 4
consecutive characters when the char that has been read is from set of chars {a,t,s,c). (bfirst letter of trig functions)and now you compare the variable with a value of trig functions.