Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added a.out
Binary file not shown.
100 changes: 100 additions & 0 deletions driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "split_service.h"

int main()
{
SplitService *ser = new SplitService(4);

User *U1 = new User(0, "u1", "Susmita", "sm@com", "11890");
ser->set_user_table("u1", U1);

User *U2 = new User(1, "u2", "Ayan", "ay@com", "11890");
ser->set_user_table("u2", U2);

User *U3 = new User(2, "u3", "Moumita", "mm@com", "11890");
ser->set_user_table("u3", U3);

User *U4 = new User(3, "u4", "Subhayan", "sb@com", "11890");
ser->set_user_table("u4", U4);

int cont = 0;
do{
cout << "Enter operation " << endl;
string op;
cin >> op;
if (op == "SHOW")
{
cout << "for a specific user?" << endl;
string ans;
cin >> ans;
if (ans == "YES" || ans == "Yes" || ans == "yes")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should follow the same format as mentioned in the problem statement at least during the interview.

{
cout << "Enter user id" << endl;
string u;
cin >> u;
ser->SHOW(u, 0);
}
else
{
ser->SHOW_ALL();
}
}
else if (op == "EXPENSE")
{
int num = 0;
string payer;
vector <string> users;
string type;
int total;
cout << "Enter payer " << endl;
cin >> payer;
cout << "Enter total " << endl;
cin >> total;
cout << "Enter no of users " << endl;
cin >> num;
cout << "enter user_ids " << endl;
for (int i = 0; i<num; i++)
{
string u;
cin >> u;
users.push_back(u);
}
cout << "Enter type of expense, EXACT, EQUAL or PERCENT " << endl;
cin >> type;
if (type == "EQUAL")
ser->EXPENSE_EQUAL(total, payer, users);
else if (type == "EXACT")
{
cout << "Enter amounts " << endl;
vector <int> amounts;
for (int i = 0; i<num; i++)
{
int amount;
cin >> amount;
amounts.push_back(amount);
}
ser->EXPENSE_EXACT(total, payer, users, amounts);
}
else if (type == "PERCENT")
{
cout << "Enter percents " << endl;
vector <float> percents;
for (int i = 0; i<num; i++)
{
float percent;
cin >> percent;
percents.push_back(percent);
}
ser->EXPENSE_PERCENT(total, payer, users, percents);
}
else
cout << "INVALID TYPE" << endl;
}
else
cout << "INVALID OPERTAION " << endl;

cout << "Press 1 to continue" << endl;
cin >> cont;
}while (cont == 1);

return 0;
}
207 changes: 207 additions & 0 deletions output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
Enter operation
SHOW
for a specific user?
n
No balances
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
YES
Enter user id
u1
No balances
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u2
Enter total
1000
Enter no of users
4
enter user_ids
u1 u2 u3 u4
Enter type of expense, EXACT, EQUAL or PERCENT
EQUAL
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
yes
Enter user id
u1
u1 owes u2: 250
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
yes
Enter user id
u2
u1 owes u2: 250
u3 owes u2: 250
u4 owes u2: 250
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
n
u1 owes u2: 250
u3 owes u2: 250
u4 owes u2: 250
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u3
Enter total
2000
Enter no of users
3
enter user_ids
u1 u2 u4
Enter type of expense, EXACT, EQUAL or PERCENT
EXACT
Enter amounts
1000 500 500
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
yes
Enter user id
u3
u1 owes u3: 1000
u2 owes u3: 250
u4 owes u3: 500
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u1
Enter total
1000
Enter no of users
1
enter user_ids
u3
Enter type of expense, EXACT, EQUAL or PERCENT
PERCENT
Enter percents
100
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
yes
Enter user id
u1
u1 owes u2: 250
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
yes
Enter user id
u3
u2 owes u3: 250
u4 owes u3: 500
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u2
Enter total
250
Enter no of users
1
enter user_ids
u3
Enter type of expense, EXACT, EQUAL or PERCENT
EXACT
Enter amounts
250
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
n
u1 owes u2: 250
u4 owes u2: 250
u4 owes u3: 500
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u4
Enter total
750
Enter no of users
2
enter user_ids
u2 u3
Enter type of expense, EXACT, EQUAL or PERCENT
PERCENT
Enter percents
25 70
invalid_entry!!!
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u4
Enter total
750
Enter no of users
2
enter user_ids
u2 u3
Enter type of expense, EXACT, EQUAL or PERCENT
EXACT
Enter amounts
250 500
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
n
u1 owes u2: 250
Press 1 to continue
1
Enter operation
EXPENSE
Enter payer
u1
Enter total
250
Enter no of users
1
enter user_ids
u2
Enter type of expense, EXACT, EQUAL or PERCENT
EQUAL
Press 1 to continue
1
Enter operation
SHOW
for a specific user?
n
No balances
Press 1 to continue
0
Loading