-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformulaSolver.h
More file actions
52 lines (41 loc) · 1.45 KB
/
formulaSolver.h
File metadata and controls
52 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef __FORMULA_SOLVER_H_
#define __FORMULA_SOLVER_H_
#include <iostream>
#include <string.h>
#include <string>
#include <map>
using namespace std;
void ReplaceStringInPlace(std::string &, const std::string &,
const std::string &);
#define OPERATOR_PRIORITY_LEVELS 2
// Estructura que contiene la configuracion de Parseo
struct eqNode
{
string equation;
float result;
char operation;
eqNode *left; // Hoja del arbol izquierda
eqNode *right; // Hoja del arbol derecha
};
class Formula
{
private:
eqNode *root; // Arbol que contiene la formula completa
map<string, float> *lista_variables; // Listado de variables que intervienen en la formula
void Parse(string, eqNode *); // parsea una formula y la coloca en el arbol correspondiente
string showFormula(eqNode *);
float calculate(eqNode *);
void deleteFormula(eqNode *);
public:
void defineVarMap(map<string, float> *); // Se apunta aqui a la variable global que contiene el mapa de variables
void addVariable(string, float); //Agrega variable
void showVariables();
void Parse(string); // parsea una formula y la coloca en el arbol correspondiente
string showFormula();
float calculate(); // Calcula el resultado de la formula
void deleteFormula();
Formula(); // Constructor por omision
Formula(string); //Constructor con formula de entrada
~Formula();
};
#endif