Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need a simple GUI for scientific calculator code C++ data strucs algorithms. Doe

ID: 3834438 • Letter: N

Question

Need a simple GUI for scientific calculator code C++ data strucs algorithms. Doesnt have to be fancy: Thanks

#include <iostream>
#include <cctype>
#include <cmath>
//ProtoTypes
void arithemeticOpr();

void addition();
void subtraction();
void multipilication();
void division();

void trigonometricFun();

void sinFun();
void cosFunction();
void tanFunction();

void logarithmicFun();

void natural();
void log();

void powerFun();

void power();
void squareRoot();

using namespace std;
//The main function
int main()
{
   //Charecter type variables to store
char letter;


//To print the header
cout << " ***************** SCIENTIFIC CALCULATOR ****************** ";
//The do while loop to reapt the program untill user enter exit
do {
//display the menu
cout << " 1 : Arithmetic Operations ";
cout << " 2 : Trigonometric Functions ";
cout << " 3 : Logarithmic Functions ";
cout << " 4 : Power Functions ";
cout << " 5 : Exit... ";
//Take the input choice
cin >> letter;
//The swich loop to process various choices
switch (letter) {
//If user select to perform Arithmetic Operations
case '1': {
// call the arithemeticOpr function
arithemeticOpr();
break;
} // end of case 1 arithmatic operation

//if user selects Trigonometric Functions
case '2': {
// call the trigonometricFun function
trigonometricFun();
break;
} // inner case 2 trignomatic
//if user selects Logarithmic Functions
case '3': {
// call the logarithmicFun function
logarithmicFun();
break;
} // end of case 3 logrithmic
//if user selects power operations
case '4': {
// call the powerFun function
powerFun();
break;
} // end of case power function
} // outer switch
} while (letter != '5'); //reepat while user not enter 5
return 0;
}

void arithemeticOpr()
{
   //Charecter type variables to store
char letter1;

//Display the sub menu
cout << " ";
cout << " 1 : Addition ";
cout << " 2 : Subtraction ";
cout << " 3 : Multipilication ";
cout << " 4 : Division ";
//read the choice
cin >> letter1;
//the swich loop to process the user selected arithematic operation
switch (letter1) {
//if user selected to add
case '1': {
// call addition function
addition();
//Break the case
break;
}
//If the user select to subtract
case '2': {
// call subtraction function
subtraction();
//break the case
break;
}
//If user selects multiplication operation
case '3': {
// call multipilication function
multipilication();
//break the case statement
break;
}
//if user selects division operation
case '4': {
// call division function
division();
//break the case
break;
}
}
}

void addition()
{
   //To store integer type result
int result;
   //Integer type variables to hold operands
int a, b;
//Display the message
cout << " Enter first number...";
//read the first number
cin >> a;
//Display the message
cout << "Enter an other number...";
//read the first number
cin >> b;
//Perform the operation and store the result in result
result = a + b;
//display the result
cout << " Result = " << result << endl;
}
void subtraction()
{
   //To store integer type result
int result;
   //Integer type variables to hold operands
int a, b;
//Display the message
cout << " Enter first number...";
//read the first number
cin >> a;
//Display the message
cout << "Enter an other number...";
//read the second number
cin >> b;
//perform the subtraction operation
result = a - b;
//display the result
cout << " Result = " << result << endl;
}
void multipilication()
{
   //To store integer type result
int result;
   //Integer type variables to hold operands
int a, b;
////Display the message
cout << " Enter first number...";
//read the first number
cin >> a;
//Display the message
cout << "Enter an other number...";

//Display the message
cin >> b;
//perform the operation and store the result in result
result = a * b;
//display the result
cout << " Result = " << result << endl;
}
void division()
{
   //To store integer type result
int result;
   //Integer type variables to hold operands
int a, b;
//Display the message
cout << " Enter first number...";

//reaad the first number
cin >> a;

//Display the message
cout << "Enter an other number...";

//Display the message
cin >> b;

//if numerator is not zero
//a logical mistake is here actally b!=0 has to be checked
//The denominator should not be zero
if (a != 0) {
//perform the operation and the result is in result
result = a / b;
//display the result
cout << " Result = " << result << endl;
}
}

void trigonometricFun()
{
//Charecter type variables to store
char letter2;

//diaplay the sub menu
cout << " ";
cout << " 1 : Sin function ";
cout << " 2 : Cos function ";
cout << " 3 : Tan function ";
//read the choice entered by the user
cin >> letter2;
//The switch to process various choices
switch (letter2) {
//If user input 1, that is Sin function
case '1': {
// call the sin function
sinFun();
//break the case
break;
}
//If user input 2, that is Cos function
case '2': {
// call the cosFunction function
cosFunction();
//break the case
break;
}
//If user input 3, that is Tan function
case '3': {
// call the tanFunction function
tanFunction();

//break the case
break;
}
} // inner switch
}

void sinFun()
{
   //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
//Display the message
cout << " Enter a number...";
//read the number from user
cin >> a1;
//perform the operation, since the result is double store it in result2
result1 = (sin(a1));
//diaply the result
cout << " Result = " << result1 << endl;
}
void cosFunction()
{
   //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
//Display the messag
cout << " Enter a number...";
//read the number from user
cin >> a1;
//perform the operation, since the result is double store it in result2
result1 = (cos(a1));
//diaply the result
cout << " Result = " << result1 << endl;
}
void tanFunction()
{
   //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
//Display the message
cout << " Enter a number...";
//read the number from user
cin >> a1;
//perform the operation, since the result is double store it in result2
result1 = (tan(a1));
//diaply the result
cout << " Result = " << result1 << endl;
}
void logarithmicFun()
{
   //Charecter type variables to store
   char letter3;

//Display the inner menu
cout << " ";
cout << " 1 : Natural log ";
cout << " 2 : log with base 10 ";
//read the user choice
cin >> letter3;
//Switch to process user choices
switch (letter3) {

//if user selects natural log
case '1': {
// call the natural Function
natural();
//break the case
break;
}
//if user selects base 10 log
case '2': {
// call the log Function
log();
//break the case
break;
}
} // end of switch
}

void natural()
{
   //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
//Display the message
cout << " Enter a number...";
//read the input number
cin >> a1;
//perform the operation
result1 = log(a1);
//display the result
cout << " Result = " << result1 << endl;
}
void log()
{
       //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
//Display the message
cout << " Enter a number...";
//read the number from user
cin >> a1;
//perform the operation
result1 = log10(a1);
//display the result
cout << " Result = " << result1 << endl;
}

void powerFun()
{
   char letter4;
//diaplay the inner menu
cout << "1) Press 1 for Power ";
cout << "2) Press 2 for Square root ";
cout << "Enter your choice....";
//read the user input
cin >> letter4;
//The switch to process user choice
switch (letter4) {
//if user selects power
case '1': {
// call the power function
power();
//break the case
break;
}
//if user selects square root
case '2': {
// call the squareRoot function
squareRoot();
//break the case
break;
}
} // end of switch
}

void power()
{
       //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
//Display the message
cout << " Enter a number...";

//read the first number
cin >> a1;

//Display the message
cout << "Enter power...";
//read the power
cin >> b1;
//perform the operation
result1 = pow(a1, b1);
//display the result
cout << " Result = " << result1 << endl;
}
void squareRoot()
{
       //to store float type result
double result1;
   //Double type variables to hold operands
double a1, b1;
   //Integer type variables to hold operands
int a;
//Display the message
cout << " Enter a number...";
//read the number
cin >> a;
//find the square root
result1 = sqrt(a);
//Display the message
cout << " Result = " << result1 << endl;
}

Explanation / Answer

//normal calucultor
//written by A.Asem
//abdelrahman.asem@hotmail.com
//All copy ritght are received www.egypower.org

#ifndef CALCULATOR_H
#define CALCULATOR_H

#include "fix.h"

class Calculator : public MyFixer
{
private:
   int str, end, // sub calculation borders
   //depending on brackets
       digit,digit1,digit2, //get number digit
       temp, temp1; //temprature variable

   vector<char> charNum;
   double num, num1, num2; //storing double number
   bool final; //final time do mathematics
  
   double getCaclNum (vector<char> &form, int &order, int &count);
   void getBorder (vector<char> &form);
   void firstRank (vector<char> &form); //trigonmetric and power
   void secondRank (vector<char> &form); //do multiplying and division
   void thirdRank (vector<char> &form); //summing and subtracting
   vector<char> _calc (vector<char> formula);
   vector<char> strToVector (string form);
   vector<char> charToVector(char form [] );
public:

   Calculator () :final(false){}  
   double calc (vector<char> formula);
   double calc(char formula []);
   double calc(string formula );
   double calc (vector<char> formula, char var, double varValue);
   double calc (char formula [], char var, double varValue);
   double calc (string formula , char var, double varValue);
  
};//end caluculator


vector<char> Calculator :: _calc (vector<char> formula)
{
       fix(formula); //fix formula to adapt it to standard math rules

   do
       {
       getBorder (formula); //set brackets
       if( str == 0 && end == formula.size() )
           final = true;
  
       firstRank (formula);
       secondRank (formula);
       thirdRank (formula);
      
       } while (!final);

       final = false;
      
   return formula;
}//end _calc
void Calculator :: getBorder (vector<char> &form)
{
   //default case  
   str = 0;
   end = form.size();
   int temp;

   //border's indexes loop
   for(temp = 0; temp < form.size(); temp++)
       {
           if(form[temp] == '(' )
               str = temp + 1;
          
           else if ( form[temp] == ')' )
           {
               end = temp - 1;
               break;
           }
       }//end border for

       //remove bracket
       if( str != 0 )
       {
          
           form.erase(form.begin() + str - 1); //remove left bracket
           str --; //str go back after removing

           form.erase(form.begin () + end); //remove right bracket
           end --; //str go back after removing left bracket
       }
   }//end getBorder

void Calculator :: firstRank (vector<char> &form) //do trignomitric and power calculation
{
       for(temp = str; temp < end; temp++)
       {
           if(isdigit(form[temp] ))
               continue;

           //power condition ^
           if( temp<form.size()-1 && form [temp] == '^' && isdigit (form [temp-1] ) &&
               (isdigit (form [temp+1] ) || (form[temp+1] == '-' && isdigit(form[temp+2]) )) )
           {
               temp += 1; //go to next num
               num2 = getCaclNum(form,temp,digit2);
               temp -= 2; //return to first num
               if(num2 < 0) temp--; //return during negative sign
               num1 = getCaclNum(form,temp,digit1);
               temp -=digit1-1; //stand on first digit
               num1 = pow(num1, double(num2) );
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin() + temp + digit1 + digit2 + 1); //ears sin and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               if(editSigns(form))
                   end--;

                   //edit formulas signs
               end += (charNum.size() - digit1 - digit2 - 1); //reassuming end

           }//end power condition
          
           else if(end > temp + 3 && form[temp] == 's' && form[temp+1] == 'i' && form[temp+2] == 'n' && form[temp+3] == 'h')
           {  
               temp +=4; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=4; //return to main position
               num1 = sinh(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 4 +digit); //erase sinh and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 4 ); //reassuming end          
           }//end cosh condition

           //sin condition
           else if(end > temp + 2 && form[temp] == 's' && form[temp+1] == 'i' && form[temp+2] == 'n' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number (angle)
               num *= M_PI / 180; //converte to grade form
               temp -=3; //return to main position
               num1 = sin(num); //calculate sin
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //ears sin and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3); //reassuming end
           }//end sin condition

           else if(end > temp + 3 && form[temp] == 'c' && form[temp+1] == 'o' && form[temp+2] == 's' && form[temp+3] == 'h')
           {  
               temp +=4; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=4; //return to main position
               num1 = cosh(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 4 +digit); //erase cosh and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 4 ); //reassuming end          
           }//end cosh condition

           else if(end > temp + 2 && form[temp] == 'c' && form[temp+1] == 'o' && form[temp+2] == 's' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=3; //return to main position
               num *= M_PI / 180; //converte to grade form
               num1 = cos(num); //calculate cos
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //ears cos and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3); //reassuming end
           }//end cos condition
          
           else if(end > temp + 3 && form[temp] == 't' && form[temp+1] == 'a' && form[temp+2] == 'n' && form[temp+3] == 'h')
           {  
               temp +=4; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=4; //return to main position
               num1 = tanh(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 4 +digit); //ears tanh and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 4 ); //reassuming end          
           }//end tanh condition


           else if(end > temp + 2 && form[temp] == 't' && form[temp+1] == 'a' && form[temp+2] == 'n' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=3; //return to main position
               num *= M_PI / 180; //converte to grade form
               num1 = tan(num); //calculate tan
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //ears tan and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3 ); //reassuming end          
           }//end tan condition

           else if(end > temp + 2 && form[temp] == 'c' && form[temp+1] == 'o' && form[temp+2] == 't' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=3; //return to main position
               num *= M_PI / 180; //converte to grade form
               num1 = atan(num); //calculate cotan
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //ears tan and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3 ); //reassuming end          
           }//end tan condition

           else if(end > temp + 2 && form[temp] == 's' && form[temp+1] == 'e' && form[temp+2] == 'c' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=3; //return to main position
               num *= M_PI / 180; //converte to grade form
               num1 = acos(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //ears tan and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3 ); //reassuming end          
           }//end tan condition

           else if(end > temp + 2 && form[temp] == 'c' && form[temp+1] == 's' && form[temp+2] == 'c' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=3; //return to main position
               num *= M_PI / 180; //converte to grade form
               num1 = asin(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //ears tan and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3 ); //reassuming end          
           }//end tan condition

       else if(end > temp + 2 && form[temp] == 'l' && form[temp+1] == 'o' && form[temp+2] == 'g' )
           {  
               temp +=3; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=3; //return to main position
               num1 = log10(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 3+digit); //erase log and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 3 ); //reassuming end          
           }//end log 10 condition
      
       else if(end > temp + 1 && form[temp] == 'l' && form[temp+1] == 'n' )
           {  
               temp +=2; //stand on the first numerical digit
               num = getCaclNum(form,temp,digit); //calculate inner number
               temp -=2; //return to main position
               num1 = log(num); //calculate sec
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin()+temp + 2+digit); //erase ln and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit - 2 ); //reassuming end          
           }//end log 10 condition

      

       }//end for
      
}//end firstRank

void Calculator ::secondRank (vector<char> &form) //do trignomitric and power calculation
{
  
       for(temp = str; temp < end; temp++)
       {

           if( temp>0 && form [temp] == '*' && isdigit (form [temp-1] ) &&
               ((temp<form.size()-1 && isdigit (form [temp+1]) )
               || ( temp<form.size()-2 && form[temp+1] == '-' && isdigit(form[temp+2]) )) )
           {
               temp += 1; //go to next num
               num2 = getCaclNum(form,temp,digit2);
               temp -= 2; //return to first num
               num1 = getCaclNum(form,temp,digit1);
               temp -=digit1-1; //stand on first digit
               num1 = num1 * num2;
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin() + temp + digit1 + digit2 + 1); //ears sin and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               if(editSigns(form)) end--; //edit formulas signs
               end += (charNum.size() - digit1 - digit2 - 1 ); //reassuming end
               temp--;

           }//end power condition

           else if( temp>0 && form [temp] == '/' && isdigit (form [temp-1] ) &&
               (isdigit (form [temp+1] ) || (form[temp+1] == '-' && isdigit(form[temp+2]) )) )
           {//finte number
               temp += 1; //go to next num
               num2 = getCaclNum(form,temp,digit2);
               temp -= 2; //return to first num
               num1 = getCaclNum(form,temp,digit1);
               temp -=digit1-1; //stand on first digit
                   num1 = num1 / num2; //do division
              
               if(num2 ==0 )
                   throw invalid_argument("Wrong Formula ");

               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin() + temp + digit1 + digit2 + 1); //ears sin and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               if(editSigns(form)) end--; //edit formulas signs
               end += (charNum.size() - digit1 - digit2 - 1 ); //reassuming end
               temp--;
              
           }//end division

       }//end for
      
}//end second Rank

void Calculator ::thirdRank (vector<char> &form)
{
  
       for(temp = str; temp < end; temp++)
       {
           if(isdigit(form[temp]))
               continue;
           if( temp>0 && form [temp] == '+' && isdigit (form [temp-1] ) &&
               (isdigit (form [temp+1] ) || (form[temp+1] == '-' && isdigit(form[temp+2]) )) )
           {
               temp += 1; //go to next num
               num2 = getCaclNum(form,temp,digit2);
               temp -= 2; //return to first num
               num1 = getCaclNum(form,temp,digit1);
               temp -=digit1-1; //stand on first digit
               num1 = num1 + num2;
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin() + temp + digit1 + digit2 + 1); //ears sin and its number
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit1 - digit2 -1 ); //reassuming end
               temp--;
           }//end summation condition

           if( temp>0 && form [temp] == '-' && isdigit (form [temp-1] ) &&
               (isdigit (form [temp+1] ) || (form[temp+1] == '-' && isdigit(form[temp+2]) )) )
           {
               temp += 1; //go to next num
               num2 = getCaclNum(form,temp,digit2);
               temp -= 2; //return to first num
               num1 = getCaclNum(form,temp,digit1);
               temp -=digit1-1; //stand on first digit
               num1 = num1 + num2;
               charNum = dtoVchar(num1); //converte number to vector of char
               form.erase(form.begin()+temp, form.begin() + temp + digit1 + digit2); //ears the numbers
               form.insert(form.begin() + temp , charNum.begin() , charNum.end()); //insert result to vector
               editSigns(form); //edit formulas signs
               end += (charNum.size() - digit1 - digit2); //reassuming end
               temp--;
           }//end subtracting condition

       }//end for
      
}//end thrid rank

vector<char> Calculator ::strToVector(string formula)
{
           vector <char> vectorFormula;

       //saving formula to
       for(temp = 0; temp < formula.size(); temp++)
       {
           vectorFormula.push_back(formula.at(temp));
       }

       return vectorFormula;
}

vector<char> Calculator ::charToVector(char formula [])
{

   int len = strlen(formula);
       vector <char> vectorFormula;

       //saving formula to
       for(int temp = 0; temp < len; temp++)
       {
           vectorFormula.push_back(formula[temp]);
       }

       return vectorFormula;
}
//getting a number from vecor of char starting in order
//treating with first point as start
double Calculator :: getCaclNum (vector<char> &form, int &order, int &count)
{
  
   bool sign = true; // 1 for positive and 0 for negative
   double result = 0; //for returning
   int digit = 0; //arrange digits
   bool part = 1; // 1 integer, 0 float
   int temp;
   count = 0; //default case of digit's count
  
   temp = order; //starting arrange

   //negative number
  
   while ( (temp > str )&& (isdigit(form[temp -1]) || form[temp-1] == '.' ) )
       temp--;
  
       if(form [temp] == '-')
       {
           sign = false;//the number is negative
           temp++;
           count++;
       }
       else if(temp > 0 && form [temp-1] == '-')
       {
           sign = false;//the number is negative
           count++;
       }

   //covering elemnts
   while( temp <form.size() && (isdigit(form[temp]) || form[temp] == '.' ) )
   {
       if(form[temp] == '.')
       {
           part = 0;
           digit = 0;
       }
       else
       {
           if(part)//integer part
               result = result * 10 + form[temp] - 48;
           else
               result = result + ( form[temp] - 48 ) * pow(10, (double)--digit);
       }
       count++; //increase digit's count
       temp++; //going to next elements
   }//end whlie

   return (sign) ? result : -1 *result;
}//end getCalcNum


   //calculate numerical formula
   double Calculator :: calc (vector<char> formula)
   {
       if(!check (formula))  
           throw invalid_argument("Wrong formula ");
      
       return charVtod(_calc(formula));
      
}//end_ calc

   double Calculator :: calc(char formula [])
   {
      
       int len = strlen(formula);
       vector <char> vectorFormula = charToVector(formula);

       if(!check (vectorFormula))  
           throw invalid_argument("Wrong formula ");
      

       return charVtod(_calc(vectorFormula));
   }

   double Calculator :: calc(string formula )
   {
       vector <char> vectorFormula = strToVector(formula);

      
       if(!check (vectorFormula))  
           throw invalid_argument("You entered wrong formula ");
      
       return charVtod(_calc(vectorFormula));
   }

   //calculate formula with a variable
   double Calculator :: calc (vector<char> formula, char var, double varValue)
   {
       if(!check(formula, var))
           throw invalid_argument("Wrong Formula");
      
           fix(formula);
           charNum = dtoVchar(varValue); //put xValue on charNum
           for(int temp = 0; temp < formula.size(); temp++)
           {
               if(formula[temp] == var)
               {
                   formula.erase(formula.begin()+temp);
                   formula.insert(formula.begin()+temp,charNum.begin(),charNum.end() );
               }

           }//end for
             
           return charVtod(_calc(formula));
      
   }//end calc of vectors with one var

   //calculate formula with a variable
   double Calculator :: calc ( char formula [], char var, double varValue)
   {
       vector <char> vectorFormula = charToVector(formula);

       if(!check(vectorFormula, var))
           throw invalid_argument("Worng formula ");

           fix(vectorFormula);
           charNum = dtoVchar(varValue); //put xValue on charNum
           for(int temp = 0; temp < vectorFormula.size(); temp++)
           {
               if(vectorFormula[temp] == var)
               {
                   vectorFormula.erase(vectorFormula.begin()+temp);
                   vectorFormula.insert(vectorFormula.begin()+temp,charNum.begin(),charNum.end() );
               }

           }//end for

           return charVtod(_calc(vectorFormula));
       }
  
   //calculate formula with a variable
   double Calculator :: calc ( string formula , char var, double varValue)
   {
      
       vector <char> vectorFormula = strToVector(formula);


       if(!check(vectorFormula, var))
           throw invalid_argument("Worng formula ");

           fix(vectorFormula);
           charNum = dtoVchar(varValue); //put xValue on charNum
           for(int temp = 0; temp < vectorFormula.size(); temp++)
           {
               if(vectorFormula[temp] == var)
               {
                   vectorFormula.erase(vectorFormula.begin()+temp);
                   vectorFormula.insert(vectorFormula.begin()+temp,charNum.begin(),charNum.end() );
               }
           }//end for
           return charVtod(_calc(vectorFormula));
       }
#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote