-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassMoneyManager.cpp
More file actions
150 lines (138 loc) · 3.58 KB
/
classMoneyManager.cpp
File metadata and controls
150 lines (138 loc) · 3.58 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// fle for class Money Manager
#include <iostream>
#include <string>
#include "classT.h"
#include "classMoneyManager.h"
#include <fstream>
#include "utils.h"
using namespace std;
void MoneyManager::loadData()
{
// read transactions from the file
// and load them up in incomeTransactions and expenseTransactions;
ifstream fin;
fin.open("data.txt");
string line;
string data;
while (getline(fin, line))
{
data += line + "\n";
}
cout << data;
fin.close();
}
void MoneyManager::storeData()
{
// write transactions present in incomeTransactions and expenseTransactions to file
ofstream out;
out.open("data.txt");
out << "Type"
<< "\tDate"
<< "\tAmount"
<< "\tNote" << endl;
string date_file, note_file;
float amount_file;
for (auto transaction : incomeTransactions)
{
date_file = transaction->date;
amount_file = transaction->amount;
note_file = transaction->note;
out << "Credit"
<< "\t" << date_file << "\t" << amount_file << "\t" << note_file << endl;
}
for (auto transaction : expenseTransactions)
{
date_file = transaction->date;
amount_file = transaction->amount;
note_file = transaction->note;
out << "Debit"
<< "\t" << date_file << "\t" << amount_file << "\t" << note_file << endl;
}
out.close();
}
void MoneyManager::addExpense()
{
string tx_date = getDate();
float tx_amount = getAmount();
string tx_note = getNote();
Transaction *transaction = new Transaction(tx_date, tx_amount, tx_note);
expenseTransactions.push_back(transaction);
balance -= tx_amount;
}
void MoneyManager::addIncome()
{
string tx_date = getDate();
float tx_amount = getAmount();
string tx_note = getNote();
Transaction *transaction = new Transaction(tx_date, tx_amount, tx_note);
incomeTransactions.push_back(transaction);
balance += tx_amount;
}
void MoneyManager::showTransaction()
{
cout << "Type"
<< "\tDate"
<< "\tAmount"
<< "\tNote" << endl;
for (auto transaction : incomeTransactions)
{
cout << "Credit"
<< "\t" << transaction->date << "\t" << transaction->amount << "\t" << transaction->note << endl;
}
for (auto transaction : expenseTransactions)
{
cout << "Debit"
<< "\t" << transaction->date << "\t" << transaction->amount << "\t" << transaction->note << endl;
}
}
void MoneyManager::showBalance()
{
cout << "Your current balance : " << balance << endl;
}
int MoneyManager::getType()
{
int typeChoice;
cout << "Select entry type : " << endl
<< "\t1. Income" << endl
<< "\t2. Expense" << endl
<< "\t3. Show recorded transaction" << endl
<< "\t4. Show balance" << endl
<< "\t5. To exit" << endl;
cin >> typeChoice;
return typeChoice;
}
void MoneyManager::addExpenseCategory()
{
}
int MoneyManager::addIncomeCategory()
{
}
int MoneyManager::runApplication()
{
cout << "Starting money manager application" << endl;
cout << "Previous transactions : " << endl;
loadData();
while (1)
{
int choice = getType();
switch (choice)
{
case 1:
addIncome();
break;
case 2:
addExpense();
break;
case 3:
showTransaction();
break;
case 4:
showBalance();
break;
case 5:
storeData();
return 1;
}
}
cout << "Stopping the application" << endl;
}