void NobracketString::divide(string Anumb,string Atype, string Bnumb, string Btype){ //need to handle different types calculation, basicly differen type just return as it is. isReturnOneNumb = false; if(Atype==Btype){ //if they are the same type; if(Atype == "frac") { Fraction* fra = new Fraction(Anumb); Fraction* frb = new Fraction(Bnumb); fra->Division(*frb); opAnswer = fra->getAnswer(); isReturnOneNumb = true; // here may need to delete the object. } else if(Atype == "int") { Integers* intnumbA = new Integers(Anumb); Integers* intnumbB = new Integers(Bnumb); intnumbA->Divide(*intnumbB); opAnswer = intnumbA->getAnswer(); //!!!!!here type has to be a "frac"!!!!! //// //delete[] intnumb; // if(opAnswer.find("/")<100) // isReturnOneNumb = false; // else isReturnOneNumb = true; } else if(Atype=="log") { Logs* lgA = new Logs(Anumb); Logs* lgB = new Logs(Bnumb); lgA->divide(*lgB); opAnswer = lgA->getAnswer(); //delete[] lg; if(opAnswer.find("/")<100){ //if the opanswer string contains "+", means it return a complex expression isReturnOneNumb = false;} else isReturnOneNumb = true; } else if(Atype=="root") { nthRoot* nthNumb = new nthRoot(Anumb); nthRoot* B = new nthRoot(Bnumb); nthNumb->divide(*B); opAnswer = nthNumb->getAns(); if(opAnswer.find("/")<100) //if the opanswer string contains "+", means it return a complex expression isReturnOneNumb = false; else isReturnOneNumb = true; }//it is handled in the calculating() else if(Atype=="pi"){ // Pi* p = new Pi(Anumb); // p->Divide(*p); // opAnswer = p->getAnswer(); isReturnOneNumb = true; } else if(Atype=="e"){ Exponential* p = new Exponential(Anumb); Exponential* b = new Exponential(Bnumb); p->Divide(*b); opAnswer = p->getAnswer(); isReturnOneNumb = true; }else if(Atype=="exp"){ Exponent* power = new Exponent(Anumb); Exponent* b = new Exponent(Bnumb); power->divide(*b); opAnswer = power->getAnswer(); if(opAnswer.find("-")<100) //if the opanswer string contains "+", means it return a complex expression isReturnOneNumb = false; else isReturnOneNumb = true; } }else{ //if not the same type } }
void NobracketString::Multip(string Anumb,string Atype, string Bnumb, string Btype){ isReturnOneNumb = false; if(Atype==Btype){ //if they are the same type; if(Atype == "frac") { Fraction* fra = new Fraction(Anumb); Fraction* frb = new Fraction(Bnumb); fra->Multiplication(*frb); opAnswer = fra->getAnswer(); isReturnOneNumb = true; // here may need to delete the object. } else if(Atype == "int") { Integers* intnumbA = new Integers(Anumb); Integers* intnumbB = new Integers(Bnumb); intnumbA->Multiply(*intnumbB); opAnswer = intnumbA->getAnswer(); //// //delete[] intnumb; isReturnOneNumb = true; } else if(Atype=="log") { Logs* lgA = new Logs(Anumb); Logs* lgB = new Logs(Bnumb); lgA->Multip(*lgB); opAnswer = lgA->getAnswer(); //delete[] lg; if(opAnswer.find("*")<100) //if the opanswer string contains "+", means it return a complex expression isReturnOneNumb = false; else isReturnOneNumb = true; } else if(Atype=="root") { nthRoot* nthNumb = new nthRoot(Anumb); nthRoot* B = new nthRoot(Bnumb); nthNumb->multiply(*B); opAnswer = nthNumb->getAns(); if(opAnswer.find("*")<100) //if the opanswer string contains "+", means it return a complex expression isReturnOneNumb = false; else isReturnOneNumb = true; }//it is handled in the calculating() else if(Atype=="pi"){ // Pi* p = new Pi(Anumb); // p->Multiply(*p); // opAnswer = p->getAnswer(); isReturnOneNumb = true; } else if(Atype=="e"){ Exponential* p = new Exponential(Anumb); p->Multiply(*p); opAnswer = p->getAnswer(); isReturnOneNumb = true; }else if(Atype=="exp"){ Exponent* power = new Exponent(Anumb); Exponent* b = new Exponent(Bnumb); power->multiply(*b); opAnswer = power->getAnswer(); if(opAnswer.find("-")<100) //if the opanswer string contains "+", means it return a complex expression isReturnOneNumb = false; else isReturnOneNumb = true; } } else{ if((Atype=="frac"&&Btype=="int")||(Btype=="frac"&&Atype=="int")){ //if not the same type Fraction* fra = new Fraction(Anumb); Fraction* frb = new Fraction(Bnumb); fra->Multiplication(*frb); opAnswer = fra->getAnswer(); isReturnOneNumb = true; }else if((Atype=="int"&&Btype=="root")||(Btype=="int"&&Atype=="root")){ nthRoot* nthNumb = new nthRoot(Anumb); nthRoot* B = new nthRoot(Bnumb); nthNumb->multiply(*B); opAnswer = nthNumb->getAns(); // if(opAnswer.find("*")<100) //if the opanswer string contains "+", means it return a complex expression // isReturnOneNumb = true; // else isReturnOneNumb = true; } else{ isReturnOneNumb=false; } } }
void NobracketString::simplifynumbers(){ //maybe need to delete the object I create here. for(int i = 0; i<somenumbs.size();i++){ string tempnumb = somenumbs[i]; if(tempnumb.find("^")<100 && tempnumb.find("log")>100){ /////this lines needs to go into Exponent* power = new Exponent(somenumbs[i]); somenumbs[i]=power->getAnswer(); if(power->canSimplifyToInt()){ type.push_back("int"); }else if(power->canSimplifyToFrac()){ type.push_back("frac"); }else{ type.push_back("exp"); } } else if(tempnumb.find("rt")<100){ nthRoot* power = new nthRoot(somenumbs[i]); //will do the simplification in constructor. somenumbs[i]=power->getSimp(); //get a string type if(power->canSimplifytoInt()){ type.push_back("int"); } else if(power->canSimpifytoFrac()){ type.push_back("frac"); }else{ type.push_back("root"); } } else if(tempnumb.find("/")<100 && tempnumb.find("p")>100){ //im each value, if it contains /, Fraction* fra = new Fraction(somenumbs[i]); somenumbs[i]=fra->getAnswer(); //change the vector number to the simplify number. tempnumb = fra->getAnswer(); if(fra->canSimplifytoInteger()) { //if it simplifies to int type.push_back("int"); } // put "int" in the vector type; else{ type.push_back("frac"); } } else if(tempnumb.find("log")<100){ Logs* lg = new Logs(somenumbs[i]); somenumbs[i]=lg->getSimplify(); if(somenumbs[i]==expression){ //if user enter a log only and it cannot be simplify // expression = lg->FinalSplit(); //try split it; if(somenumbs[i]==expression){ //if the log cannot be split, do nothing. }else{ somenumbs.erase(somenumbs.begin()); type.clear(); separateString(); simplifynumbers(); } } if(lg->canSimplifytoInt()){ //check if it can be simplified type.push_back("int"); //if it simplifies to int, put "int" to vector type; } else if(lg->canSimplifytoFra()){ type.push_back("frac"); //else if it simplifies to fraction, put "fra" to vector type; }else{ type.push_back("log"); ////cout<<"in the log to log here"<<endl; } } else if(tempnumb.find("Pi")<100||tempnumb.find("pi")<100){ type.push_back("pi"); } else if(tempnumb.find("e")<100){ type.push_back("e"); }else{ type.push_back("int"); } } }