Question: i need to add sin , con,tan to this code i tried to add it the same way as + , * , / ,
i need to add sincon,tan to this code i tried to add it the same way as but it did not work and crashed. void CalFrame::OnClearButtonClickwxCommandEvent& event
textControlClear;
void CalFrame::OnCalculatewxCommandEvent& event
wxString expression textControlGetValue;
double result;
if EvaluateExpressionexpression result
textControlSetValuewxString::Formatg result;
else
textControlSetValueError;
void CalFrame::OnBackspacewxCommandEvent& event
wxString currentValue textControlGetValue;
if currentValue.empty
currentValue.RemoveLast;
textControlSetValuecurrentValue;
bool IsOperatorchar c
return c c c c ;
std::vector Tokenizeconst wxString& expression
std::vector tokens;
std::string number;
for char c : expression.ToStdString
if IsOperatorc
if number.empty
tokens.pushbacknumber;
number.clear;
tokens.pushbackstd::string c; Convert char to string
else if isdigitc c
number.pushbackc;
if number.empty
tokens.pushbacknumber;
return tokens;
bool CalFrame::EvaluateExpressionconst wxString & expression, double& result
std::vector tokens Tokenizeexpression;
try
std::vector stack;
result std::stodtokens;
for sizet i ; i tokens.size; i
std::string op tokensi;
double nextNum std::stodtokensi ;
if op result nextNum;
else if op result nextNum;
else if op result nextNum;
else if op result nextNum;
return true;
catch const std::exception&
return false;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
