I am doing a calculator, and I need a storage for my built-in function.
Currently, I have a vector contains all the cmath function names to be used.
I planned to have a user function, so I need an additional vector to identify the properties.
The plan are either:
use 3 vectors, all paired up:
- string for names;
- int for parameters
if 0 -> variable
if 1 -> function(x)
if 2 -> function(x,y)
if -1 -> function(x,y,...) (for sum or max, maybe?)
etc...
- double for it's value, if parameter is 0.
or, using 3 paired vectors which are:
- string and bool for the main list (some sort like an index)
- string and double for variables
- string and int for functions
Using the first method, there will be so much waste of memory on unused value @function's double (my thought, is it?)
Is the second method is better than the first one?
Any better suggestion?
Is it better in term of memory?
Well, I also found out about pair<a, b>, but it still confuses me how to work on it... (actually, I'm still weak in pointer)
I'm using multiple vector because it's easy for me to access the specific element.
*Just opened the map section, and it didn't give you the ability to push and resize.
Currently, I'm using 4 vectors:
- a <string> for main list,
- an <int> for the parameter
- another <string> for variable list
- <double> for variable value
Another string may be added for the function's equation (haven't done the main code yet ^^!)
If the parameter is 0, the entry will be added automatically to variable list
I have some default pre-defined string, such as "sin", "cos" and "pi". User can add specific variable (say: six = 6), and they can clear out their variables (resize to the limit of the pre-defined list and it'll be trimmed).
I'm thinking now about clearing it out one by one.
Is this 4 vectors better than the previous two?