-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
226 lines (218 loc) · 7.99 KB
/
main.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <ios> //used to get stream size
#include <limits> //used to get numeric limits
#include <stdlib.h>
using namespace std;
#include "./include/ExpenseManager.hh"
#include "./include/Expense.hh"
#include "./include/Commodity.hh"
#include "./include/Date.hh"
#ifdef WIN32
#define clrscr() system("cls")
#define pause() system("pause")
#endif
#ifdef __linux__
#define clrscr() system("clear")
#define pause() cout << "Press enter to continue...", cin.get()
#endif
/*
M E N U :-
Options:
[01] - Manage Expenses
[01] - Add new Expense
[02] - View existing Expenses
[03] - Delete an existing Expense
[04] - Calculate Expenditure
[05] - View all expenses
[-1] - Back
[02] - Manage Commodity Types
[01] - Add new Commodity Type
[02] - View existing Commodity Types
[03] - Delete an existing Commodity Type
[-1] - Back
[-1] - Exit
*/
int main()
{
ExpenseManager::readFromCSV();
long long choice = 0;
while (choice != -1)
{
clrscr();
cout << "\n\n";
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout << "--- || E X P E N S E M A N A G E R || ---\n";
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout << "\n\n";
cout << "|~~~~~~~~~~~~~~~~~ HOME ~~~~~~~~~~~~~~~~~~|";
cout << "\n\n";
cout << "Options:\n"
<< endl;
cout << "[01] - Manage Expenses" << endl;
cout << "[02] - Manage Commodity Types\n"
<< endl;
cout << "[-1] - Exit\n"
<< endl;
cout << "Enter your choice: ";
cin >> choice;
while ((choice > 2 || choice < 1) && choice != -1)
{
cout << "\nInvalid choice.\nPlease enter again: ";
cin >> choice;
}
cout << "\n-------------------------------------------\n\n";
if (choice == 1)
{
long long subChoice = 0;
while (subChoice != -1)
{
clrscr();
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout << "--- || E X P E N S E M A N A G E R || ---\n";
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout << "\n\n";
cout << "|~~~~~~~~~~~~ MANAGE EXPENSES ~~~~~~~~~~~~|";
cout << "\n\n";
cout << "Options:\n"
<< endl;
cout << "[01] - Add new Expense" << endl;
cout << "[02] - View an existing Expense" << endl;
cout << "[03] - Delete an existing Expense" << endl;
cout << "[04] - Calculate Expenditure" << endl;
cout << "[05] - View all Expenses\n"
<< endl;
cout << "[-1] - Back\n"
<< endl;
cout << "Enter your choice: ";
cin >> subChoice;
while ((subChoice < 1 || subChoice > 5) && subChoice != -1)
{
cout << "Invalid choice. Please enter again: ";
cin >> subChoice;
}
cout << "\n-------------------------------------------\n\n";
if (subChoice == 1)
{
Expense expense;
expense.inputDetails(1);
ExpenseManager::addExpense(expense);
cout << "\n\nAdd another expense with the same date? (Y for Yes || N for No): ";
char choice;
cin >> choice;
while (choice != 'Y' && choice != 'N')
{
cout << "Invalid choice. Please enter again: ";
cin >> choice;
}
cout << "\n\n";
while (choice == 'Y')
{
Date _date = expense.getDate();
expense.inputDetails(0);
expense.setDate(_date);
ExpenseManager::addExpense(expense);
cout << "\n\nAdd another expense with the same date? (Y for Yes || N for No): ";
cin >> choice;
while (choice != 'Y' && choice != 'N')
{
cout << "Invalid choice. Please enter again: ";
cin >> choice;
}
cout << "\n\n";
}
}
else if (subChoice == 2)
{
Expense expense = ExpenseManager::getExpenseDetails();
if (expense.getId() != -1)
expense.printDetails();
}
else if (subChoice == 3)
{
Expense expense = ExpenseManager::getExpenseDetails();
if (expense.getId() != -1)
ExpenseManager::removeExpense(expense);
}
else if (subChoice == 4)
{
ExpenseManager::calculateExpenditure();
}
else if (subChoice == 5)
{
ExpenseManager::printExpenses();
}
cout << "\n\n-------------------------------------------\n\n";
if (subChoice != -1)
{
cin.ignore(numeric_limits<streamsize>::max(), '\n');
pause();
}
}
}
else if (choice == 2)
{
long long subChoice = 0;
while (subChoice != -1)
{
clrscr();
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout << "--- || E X P E N S E M A N A G E R || ---\n";
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout << "\n\n";
cout << "|~~~~~~~~ MANAGE COMMODITY TYPES ~~~~~~~~~|";
cout << "\n\n";
cout << "Options:\n"
<< endl;
cout << "[01] - Add new Commodity Type" << endl;
cout << "[02] - View existing Commodity Types" << endl;
cout << "[03] - Delete an existing Commodity Type\n"
<< endl;
cout << "[-1] - Back\n"
<< endl;
cout << "Enter your choice: ";
cin >> subChoice;
while ((subChoice < 1 || subChoice > 3) && subChoice != -1)
{
cout << "Invalid choice. Please enter again: ";
cin >> subChoice;
}
cout << "\n-------------------------------------------\n\n";
if (subChoice == 1)
{
string commodityType;
cout << "Enter Commodity Type: ";
getline(cin >> ws, commodityType);
ExpenseManager::addCommodityType(commodityType);
}
else if (subChoice == 2)
{
ExpenseManager::printCommodityTypes();
}
else if (subChoice == 3)
{
ExpenseManager::printCommodityTypes();
ExpenseManager::removeCommodityType(ExpenseManager::getCommodityType());
}
cout << "\n\n-------------------------------------------\n\n";
if (subChoice != -1)
{
if (subChoice - 1)
cin.ignore(numeric_limits<streamsize>::max(), '\n');
pause();
}
}
}
else if (choice == -1)
{
cout << "Exiting...\n"
<< endl;
cout << "-------------------------------------------\n\n";
}
}
ExpenseManager::writeToCSV();
clrscr();
return 0;
}