Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. string SpaceRemoval(string & EquationText)
  2. {
  3. string NewEquationText = "";
  4.  
  5. // check every character
  6. for (int i = 0; i < EquationText.length(); i++)
  7. {
  8. if (EquationText[i] != ' ') // if the character is not a ' ' then add it to the NewEquationText
  9. {
  10. NewEquationText += EquationText[i];
  11. }
  12. }
  13.  
  14. // return the NewEquationText
  15. return NewEquationText;
  16. }
  17.  
  18. second part
  19. bool GetEquation()
  20. {
  21. // Input equation
  22. cout << "Equation F(x) = ";
  23. cin >> EquationText;
  24.  
  25. // Add Parentheses in the equation
  26. AddParentheses(EquationText);
  27.  
  28. // Remove extra spaces in the equation
  29. EquationText = SpaceRemoval(EquationText);
  30.  
  31. // Check if the equation is valid
  32. return EquationValidation(EquationText);
  33. }
  34.  
  35. final part
  36. #include "Header.h"
  37.  
  38. int main()
  39. {
  40.  
  41. while(true)
  42. {
  43. // Get Equation
  44. if (GetEquation())
  45. {
  46. // it's a valid equation
  47. calculateExpression(EquationText)
  48. }
  49. else
  50. {
  51. // it's a invalid equation
  52. cout << "invalid equationnn";
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement