botgob

Allmän lösning

Mar 7th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. vector<string> split(string a, char c) {
  8.     vector<string> ekvVector;
  9.     string tmp = "";
  10.     for (int i = 0; i < a.size(); i++) {
  11.         if (a[i] == c) {
  12.             ekvVector.push_back(tmp);
  13.             tmp = "";
  14.         } else {
  15.             tmp += a[i];
  16.         }
  17.     }
  18.     if (tmp != "") ekvVector.push_back(tmp);
  19.     return ekvVector;
  20. }
  21. int skitMetod(string a, int yType) {
  22.     int endResult = 0;
  23.     int bPos = 0;
  24.     int ePos = 0;
  25.     for (int i = 0; i < a.size(); i++) {
  26.         if (a[i] == 'y') {
  27.             bPos = i;
  28.             if (yType == 0) {
  29.                 a.erase(bPos, 4);
  30.                 break;
  31.             } else if (yType == 1) {
  32.                 a.erase(bPos, 5);
  33.                 break;
  34.             } else if (yType == 2) {
  35.                 a.erase(bPos, 2);
  36.                 break;
  37.             }
  38.         }
  39.     }
  40.     if (a != "") {
  41.         endResult = stoi(a);
  42.     } else {
  43.         endResult = 1;
  44.     }
  45.     return endResult;
  46. }
  47.  
  48. int main() {
  49.     string ekvString = "";
  50.     vector<string> ekvList;
  51.     cout << "Skriv in din ekvation i formen av ayBis+byPrim+cyF" << "\n";
  52.     cin >> ekvString;
  53.     cout << "\n";
  54.     ekvList = split(ekvString, '+');
  55.     double a, b, c;
  56.     string yBis = "yBis";
  57.     cout << ekvList.size() << "\n";
  58.     for (int i = 0; i < ekvList.size(); i++) {
  59.         if (ekvList[i].find(yBis) != string::npos) {
  60.             cout << "yBis found!" << "\n";
  61.             cout << skitMetod(ekvList[i], 0) << "\n";
  62.             a = skitMetod(ekvList[i], 0);
  63.         } else if (ekvList[i].find("yPrim") != string::npos) {
  64.             cout << "yPrim found!" << "\n";
  65.             cout << skitMetod(ekvList[i], 1) << "\n";
  66.             b = skitMetod(ekvList[i], 1);
  67.         } else if (ekvList[i].find("yF") != string::npos) {
  68.             cout << "yF found!" << "\n";
  69.             cout << skitMetod(ekvList[i], 2) << "\n";
  70.             c = skitMetod(ekvList[i], 2);
  71.         }
  72.     }
  73.    
  74.     b = b / a;
  75.     c = c / a;
  76.  
  77.     double root1 = ((b / 2)*(-1)) + (sqrt((b / 2)*(b / 2) - c));
  78.     double root2 = ((b / 2)*(-1)) - (sqrt((b / 2)*(b / 2) - c));
  79.  
  80.     cout << "\n" << "C1e^(" << root1 << "x) + C2e^(" << root2 << "x)\n" << "\n";
  81.  
  82. #ifdef _DEBUG
  83.         system("pause");
  84. #endif // _DEBUG
  85. }
Advertisement
Add Comment
Please, Sign In to add comment