diff --git a/Splitwise.h b/Splitwise.h new file mode 100644 index 0000000..c637645 --- /dev/null +++ b/Splitwise.h @@ -0,0 +1,128 @@ +#include +#include +#include +#define no_of_user 4 +using namespace std; +class Splitwise +{ + vector> balanceSheet; + vector users; + public: + + + Splitwise(vector users) + { + for(int i=0;iusers.push_back(users[i]); + balanceSheet.resize(no_of_user,vector(no_of_user)); + } + void showAll() + { + bool flag = false; + for(int i=0;i token) + { + if(token.size()==0) + return; + if(token[0].compare("SHOW")==0) + { + if(token.size()==2) + { + showId(token[1]); + } + else + showAll(); + } + else //EXPENSE + { + int i = findUser(token[1]); + double amount = stoi(token[2]); + int number = stoi(token[3]); + if(token[4+number].compare("EQUAL")==0) + { + //cout<<"EQUAL "< token,int number,int id,double amount) + { + //return; + for(int i=4;i token,int number,int id,double amount) + { + + for(int i=4;i<4+number;i++) + { + int percent = stoi(token[i+1+number]); + //cout< token,int number,int id,double amount) + { + for(int i=4;i<4+number;i++) + { + int amt = stoi(token[i+1+number]); + balanceSheet[id][findUser(token[i])] += amt; + } + } + int findUser(string uid) + { + int i=0; + for(;i +#include +#include +using namespace std; +class User{ + string userid; + string name, email; + long int mobile; + public: + User(string userid="",string name="",string email="",long int mobile=0) + { + this->userid = userid; + this->name = name; + this->email = email; + this->mobile = mobile; + } + string getName() + { + return name; + } + string getId() + { + return userid; + } + string getEmail() + { + return email; + } + +}; diff --git a/driver b/driver new file mode 100755 index 0000000..4561f0d Binary files /dev/null and b/driver differ diff --git a/driver.cpp b/driver.cpp new file mode 100644 index 0000000..208c230 --- /dev/null +++ b/driver.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include "User.h" +#include "Splitwise.h" +#define no_of_user 4 +using namespace std; + +vector generateTokens(string s) +{ + vector tokens; + int n = s.length(); + for(int i=0;i users; + users.push_back(u1); + users.push_back(u2); + users.push_back(u3); + users.push_back(u4); + Splitwise sw(users); + //sw.showAll(); + int n; + cin>>n; + //cout< tokens = generateTokens(s); + sw.Call(tokens); + n--; + } + return 0; +} diff --git a/driver.o b/driver.o new file mode 100644 index 0000000..a786591 Binary files /dev/null and b/driver.o differ