-
Notifications
You must be signed in to change notification settings - Fork 0
/
REPL.h
90 lines (72 loc) · 2.35 KB
/
REPL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
@author: Shubhayu Das
* ax+b=c is type 1
* ax+by=c;dx+ey=f is type 2
* ax+b=cx+d is type 3
* ax^2+bx+c=d is type 4
* a^(bx+c)=d^(ex+f) is type 7
* |ax+b|=cx+d is type 9
*/
#pragma once
#include <string>
#include <vector>
#include <utility>
#include <iterator>
#include <sstream>
#include <iostream>
#include <stdexcept>
#include"Task1.h"
#include"Task2.h"
#include"Task3.h"
#include"Task4.h"
#include"Task7.h"
#include"Task9.h"
using namespace std;
class REPL
{
public:
REPL();
REPL(string);
REPL(const REPL &);
~REPL();
void detectType();
int getType() const;
void setCoeff(vector<pair<string, string>>);
void displayAnswer();
void run();
vector<pair<string, string>> getCoeff() const;
private:
void split(string &inp, char delimiter, vector<string> &parts)
{
stringstream ss(inp);
string item;
while (getline(ss, item, delimiter))
parts.push_back(item);
}
int isValidOneVariable(pair<string, string> inp, string var)
{
size_t first = inp.first.find(var), second = inp.second.find(var);
if (first != string::npos && second != string::npos)
return 1;
else if (first != string::npos || second != string::npos)
return 2;
return 0;
}
int isValidTwoVariable(vector<pair<string, string>> inp, string var1, string var2)
{
size_t first_L_X = inp[0].first.find(var1), first_L_Y = inp[0].first.find(var2);
size_t first_R_X = inp[0].second.find(var1), first_R_Y = inp[0].second.find(var2);
bool first = (first_L_X != string::npos && first_L_Y != string::npos) || (first_R_X != string::npos && first_R_Y != string::npos);
if(!first)
return -1;
size_t second_L_X = inp[1].first.find(var1), second_L_Y = inp[1].first.find(var2);
size_t second_R_X = inp[1].second.find(var1), second_R_Y = inp[1].second.find(var2);
bool second = (second_L_X != string::npos && second_L_Y != string::npos) || (second_R_X != string::npos && second_R_Y != string::npos);
if(!second)
return -1;
return 2;
}
short _type; // Stores the type of the equation
vector<pair<string,string>> _coefficients; // stores the LHS and RHS
string _input; // This is given by the user
};