Вы находитесь на странице: 1из 4

#include <cstring> #include <math.

h> #include <QString> class cQuadCTS{ private: QString strResult; QString fArgument; QString sArgument; QString strsqUnkown; QString straloUnkown; QString strvariable; double sqUnknown; double aloUnkown; double variable; double extraAgmt; double dresult; int sqDivide; public: void obtain(QString str) { str = str.toLower(); strResult = str + "=0"; int i(0); while(str[i].isDigit() || str[i].isLetter() || str[i] == '^') i++; QString tempstr = str; strsqUnkown = tempstr.remove(i,str.length()); str.remove(0,i); tempstr = str; fArgument = tempstr.remove(1,str.length()); str.remove(0,1); i = 0; while(str[i].isDigit() || str[i].isLetter()) i++; tempstr = str; straloUnkown = tempstr.remove(i,str.length()); str.remove(0,i); tempstr = str; sArgument = tempstr.remove(1,str.length()); str.remove(0,1); strvariable = str; } void algo() { //--last variable-//[3x^2+6x-4=0] //gets last arguement (known variable) variable = strvariable.toDouble();

if(sArgument == "-") variable = -variable; //switchs it using linear equation variable = -variable; strResult = strResult + "\n" + strsqUnkown + fArgument + straloUnkown + "=" + QString::number(variable); //--first variable-//[3x^2+6x=4] //returns 0 if square root variable has 0 parameter if(!strsqUnkown[0].isDigit()) sqDivide = 0; int i(0); while(strsqUnkown[i].isDigit()) i++; QString temstr = strsqUnkown; //gets squre root variable temstr.remove(i,temstr.length()); //remove main square root variable's parameters strsqUnkown.remove(0,i); //converts it to int sqDivide = temstr.toInt(); //checks for sqDivide if it's 0 or not //[x^2+2x=4/3] if(sqDivide != 0) { temstr = straloUnkown; i = 0; while(temstr[i].isDigit()) i++; temstr.remove(i,temstr.length()); aloUnkown = temstr.toDouble(); aloUnkown /= sqDivide; variable /= sqDivide; straloUnkown.remove(0,i); straloUnkown = QString::number(aloUnkown) + straloUnkown; strResult = strResult + "\n" + strsqUnkown + fArgument + straloUnkow n + "=" + QString::number(variable); } else { temstr = straloUnkown;

temstr.remove(straloUnkown.length()-1,1); aloUnkown = temstr.toDouble(); i = 0; while(straloUnkown[i].isDigit()) i++; straloUnkown.remove(0,i); straloUnkown = QString::number(aloUnkown) + straloUnkown; } //Inputting the extra variable.. //[x^2+2x+(1^2)=4/3+(1^2)] extraAgmt = aloUnkown/2; temstr = "+(" + fArgument + QString::number(extraAgmt) + ")^2"; strResult = strResult + "\n" + strsqUnkown + fArgument + straloUnkown + temstr + "=" + QString::number(variable) + temstr; //simplyfying it //[[x+1]^2=7/3] size_t len = strsqUnkown.indexOf("^"); strsqUnkown.remove(len,strsqUnkown.length()); variable += pow(extraAgmt,2); strResult = strResult + "\n" + "[" + strsqUnkown + fArgument + QString:: number(extraAgmt) + "]^2" + "=" + QString::number(variable); //final step(s) //[x+1=sqrt(7/3)] variable = sqrt(variable); strResult = strResult + "\n" + strsqUnkown + fArgument + QString::number (extraAgmt) + "=" "\b" + QString::number(variable) + "\n"; //final step :D if(fArgument == "-") { dresult = variable + extraAgmt; strResult = strResult + "\nx=" + QString::number(variable) + "+" + Q String::number(extraAgmt) + "\n =" + QString::number(dresult) + "\nor"; dresult = -variable + extraAgmt; strResult = strResult + "\nx=" + QString::number(-variable) + "+" + QString::number(extraAgmt) + "\n =" + QString::number(dresult); } else if(fArgument == "+") { dresult = variable - extraAgmt; strResult = strResult + "\nx=" + QString::number(variable) + "-" + Q String::number(extraAgmt) + "\n =" + QString::number(dresult) + "\nor"; dresult = -variable - extraAgmt; strResult = strResult + "\nx=" + QString::number(-variable) + "-" + QString::number(extraAgmt) + "\n =" + QString::number(dresult);

} } QString result() { return strResult; } }; void removeSpaces(QString &pstr) { for(int i = 0; i < pstr.size(); i++) if(pstr.at(i).isSpace()) { pstr.remove(i,1); i--; } }