Advertisement
fntasticccc

advanced calculator part 1

Apr 25th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. // ConsoleApplication187.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8. #include <iterator>
  9. #include <algorithm>
  10.  
  11.  
  12. int main()
  13. {
  14.     std::vector<char> opStack;
  15.     std::vector<std::string> operand;
  16.     bool operandGefunden = false;
  17.     std::string holder;
  18.    
  19.     std::string inputString;
  20.     std::cout << "Rechnung eingeben..." << std::endl;
  21.     std::getline(std::cin, inputString);
  22.     std::string::iterator end_point = std::remove(inputString.begin(), inputString.end(), ' ');
  23.     inputString.erase(end_point, inputString.end());
  24.  
  25.     int found = inputString.find_last_of("+-*/");
  26.  
  27.    
  28.  
  29.     for (int i = 0; i < inputString.size(); i++)
  30.     {  
  31.         if (inputString[i] != '+' && inputString[i] != '-' && inputString[i] != '*' && inputString[i] != '/')
  32.         {
  33.             holder.push_back(inputString[i]);
  34.         }
  35.  
  36.         else
  37.         {
  38.             if (i == found)
  39.             {
  40.                 opStack.push_back(inputString[i]);
  41.                 operand.push_back(holder);
  42.                 holder == "";
  43.                 operand.push_back({ inputString.begin() + i + 1, inputString.end() });
  44.                 break;
  45.             }
  46.             opStack.push_back(inputString[i]);
  47.             operand.push_back(holder); 
  48.             holder = "";
  49.         }
  50.     }  
  51.  
  52.  
  53.     std::cout << "operatoren" << std::endl;
  54.     for (auto a : opStack)
  55.     {
  56.         std::cout << a << " ";
  57.     }
  58.     std::cout << std::endl;
  59.     std::cout << "Operanden:" << std::endl;
  60.     for (auto a : operand)
  61.     {
  62.         std::cout << a << " ";
  63.     }
  64.     std::cout << std::endl;
  65.  
  66.     system("PAUSE");
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement