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
|
void parse_formula(const std::string & formula, operation_type & operation, int & x_col, int & x_row, int & y_col, int & y_row)
{
// This function should parse <formula>, and then set <operation>, <x_col>, <x_row>, <y_col>, and <y_row>
// Implementation of this function depends on the assumed format of a formula
}
float get_cell_value(int col, int row)
{
const std::string & str = S[col][row];
if(std::isalpha(str[0])) // formula
{
int x_col, x_row, y_col, y_row;
operation_type op;
parse_formula(str, op, x_col, x_row, y_col, y_row);
float x = get_cell_value(x_col, x_row);
float y = get_cell_value(y_col, y_row);
switch(op)
{
case operation_addition: return x + y;
case operation_substraction: return x - y;
...
}
}
else // number
{
std::stringstream buf(str);
float num;
buf >> num;
return num;
}
}
|