Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- vector<string> split(string a, char c) {
- vector<string> ekvVector;
- string tmp = "";
- for (int i = 0; i < a.size(); i++) {
- if (a[i] == c) {
- ekvVector.push_back(tmp);
- tmp = "";
- } else {
- tmp += a[i];
- }
- }
- if (tmp != "") ekvVector.push_back(tmp);
- return ekvVector;
- }
- int skitMetod(string a, int yType) {
- int endResult = 0;
- int bPos = 0;
- int ePos = 0;
- for (int i = 0; i < a.size(); i++) {
- if (a[i] == 'y') {
- bPos = i;
- if (yType == 0) {
- a.erase(bPos, 4);
- break;
- } else if (yType == 1) {
- a.erase(bPos, 5);
- break;
- } else if (yType == 2) {
- a.erase(bPos, 2);
- break;
- }
- }
- }
- if (a != "") {
- endResult = stoi(a);
- } else {
- endResult = 1;
- }
- return endResult;
- }
- int main() {
- string ekvString = "";
- vector<string> ekvList;
- cout << "Skriv in din ekvation i formen av ayBis+byPrim+cyF" << "\n";
- cin >> ekvString;
- cout << "\n";
- ekvList = split(ekvString, '+');
- double a, b, c;
- string yBis = "yBis";
- cout << ekvList.size() << "\n";
- for (int i = 0; i < ekvList.size(); i++) {
- if (ekvList[i].find(yBis) != string::npos) {
- cout << "yBis found!" << "\n";
- cout << skitMetod(ekvList[i], 0) << "\n";
- a = skitMetod(ekvList[i], 0);
- } else if (ekvList[i].find("yPrim") != string::npos) {
- cout << "yPrim found!" << "\n";
- cout << skitMetod(ekvList[i], 1) << "\n";
- b = skitMetod(ekvList[i], 1);
- } else if (ekvList[i].find("yF") != string::npos) {
- cout << "yF found!" << "\n";
- cout << skitMetod(ekvList[i], 2) << "\n";
- c = skitMetod(ekvList[i], 2);
- }
- }
- b = b / a;
- c = c / a;
- double root1 = ((b / 2)*(-1)) + (sqrt((b / 2)*(b / 2) - c));
- double root2 = ((b / 2)*(-1)) - (sqrt((b / 2)*(b / 2) - c));
- cout << "\n" << "C1e^(" << root1 << "x) + C2e^(" << root2 << "x)\n" << "\n";
- #ifdef _DEBUG
- system("pause");
- #endif // _DEBUG
- }
Advertisement
Add Comment
Please, Sign In to add comment