-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathExpenseReport.cpp
43 lines (34 loc) · 1.24 KB
/
ExpenseReport.cpp
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
#include <chrono>
#include <iostream>
#include <iterator>
#include "ExpenseReport.h"
using namespace std;
void printReport(list<Expense> expenses)
{
int total = 0;
int mealExpenses = 0;
auto now = chrono::system_clock::to_time_t(chrono::system_clock::now());
cout << "Expenses " << ctime(&now);
for (list<Expense>::iterator expense = expenses.begin(); expense != expenses.end(); ++expense) {
if (expense->type == BREAKFAST || expense->type == DINNER) {
mealExpenses += expense->amount;
}
string expenseName = "";
switch (expense->type) {
case DINNER:
expenseName = "Dinner";
break;
case BREAKFAST:
expenseName = "Breakfast";
break;
case CAR_RENTAL:
expenseName = "Car Rental";
break;
}
string mealOverExpensesMarker = (expense->type == DINNER && expense->amount > 5000) || (expense->type == BREAKFAST && expense->amount > 1000) ? "X" : " ";
cout << expenseName << '\t' << expense->amount << '\t' << mealOverExpensesMarker << '\n';
total += expense->amount;
}
cout << "Meal expenses: " << mealExpenses << '\n';
cout << "Total expenses: " << total << '\n';
}