-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.cc
More file actions
127 lines (117 loc) · 3.78 KB
/
Copy pathInheritance.cc
File metadata and controls
127 lines (117 loc) · 3.78 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
#define LARGE 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define sz(x) (ll)x.size()
#define present(c,x) ((c).find(x) != (c).end())
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
class Expense{
private:
string expenseid;
string itemId;
string expensetype;
int amountInUsd;
string sellerType;
public:
Expense(string expenseid, string itemId, string expensetype, int amountInUsd, string sellerType){
this->expenseid = expenseid;
this->itemId = itemId;
this->expensetype = expensetype;
this->amountInUsd = amountInUsd;
this->sellerType = sellerType;
}
int getAmountInUsd(){
return amountInUsd;
}
string getSellerType(){
return sellerType;
}
void printExpense(int x);
};
void Expense::printExpense(int x){
cout << "Expense ID: " << expenseid << endl;
cout << "Item ID: " << itemId << endl;
cout << "Expense Type: " << expensetype << endl;
cout << "Amount in USD: " << amountInUsd << endl;
cout << "Seller Type: " << sellerType << endl;
cout << "x: " << x << endl;
}
class Rule {
public:
virtual bool evaluate(vector<Expense>& expenses) = 0;
virtual ~Rule() = default;
};
class TotalExpenseLimitRule : public Rule{
private:
int totalExpenseLimit;
public:
TotalExpenseLimitRule(int totalExpenseLimit){
this->totalExpenseLimit = totalExpenseLimit;
}
bool evaluate(vector<Expense>& expenses) override{
int sum = 0;
for(auto e : expenses){
sum+=e.getAmountInUsd();
if(sum > totalExpenseLimit){
return true;
}
}
return false;
}
};
class ExpenseLimitRule : public Rule{
private:
int expenseLimit;
string sellerType;
public:
ExpenseLimitRule(int expenseLimit, string sellerType){
this->expenseLimit = expenseLimit;
this->sellerType = sellerType;
}
bool evaluate(vector<Expense>& expenses) override{
for(auto e : expenses){
if(e.getAmountInUsd() > expenseLimit && e.getSellerType() == sellerType){
return true;
}
}
return false;
}
};
bool evaluateRule(vector<unique_ptr<Rule>>& rules, vector<Expense>& expenses) {
for (auto& rule : rules) {
if (rule->evaluate(expenses)) {
return true;
}
}
return false;
}
int main() {
vector<unique_ptr<Rule>> rules;
time_t timestamp;
time(×tamp);
cout << ctime(×tamp);
rules.push_back(make_unique<TotalExpenseLimitRule>(1000));
rules.push_back(make_unique<ExpenseLimitRule>(1000, "restaurant"));
vector<Expense> expenses = {Expense("1", "Item1", "Food", 25, "restaurant"), Expense("2", "Item2", "Food", 25, "restaurant"), Expense("3", "Item3", "Food", 25, "restaurant"), Expense("4", "Item4", "Food", 25, "restaurant")};
bool result = evaluateRule(rules, expenses);
// for(auto e : expenses){
// e.printExpense(1);
// }
cout << result << endl;
}