-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdrawDepositNode.h
188 lines (174 loc) · 4.67 KB
/
withdrawDepositNode.h
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
#include <iostream>
#include <string>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <ctime>
#include <cmath>
// #include "invalidOption.h"
#pragma warning(disable : 4996)
using namespace std;
struct withdrawDepositNode
{
long accountNumber;
long double cashAmount;
bool withdrawCash;
bool depositCash;
withdrawDepositNode *next;
withdrawDepositNode *prev;
};
class withdrawDepositQueue
{
private:
withdrawDepositNode *front;
withdrawDepositNode *rear;
public:
withdrawDepositQueue()
{
front = rear = NULL;
}
bool isEmpty()
{
if (rear == NULL && front == NULL)
{
return true;
}
else
{
return false;
}
}
void enqueue()
{
withdrawDepositNode *temp = new withdrawDepositNode();
int opt = 0;
string flag = "";
cout << "\t\t\t\t Kindly choose from the following two options: 1) Withdraw Cash (cheque) or 2) Deposit Cash -> ";
// cin >> opt;
int num = opt;
invalidOption(num);
opt = num;
if (opt == 1)
{
temp->withdrawCash = true;
temp->depositCash = false;
flag = "Withdraw Cash";
}
else if (opt == 2)
{
temp->depositCash = true;
temp->withdrawCash = false;
flag = "Deposit Cash";
}
else
{
cout << "\t\t\t\t Wrong option entered, press any key to return to menu." << endl;
_getch();
return;
}
char confirmation;
cout << "\t\t\t\t Kindly write down your Account Number -> ";
// cin >> temp->accountNumber;
int num2 = temp->accountNumber;
mustBeInteger(num2);
temp->accountNumber = num2;
cout << "\t\t\t\t Kindly write down the cash amount -> ";
// cin >> temp->cashAmount;
int num3 = temp->cashAmount;
mustBeInteger(num3);
temp->cashAmount = num3;
cout << "\t\t\t\t----------" << endl;
cout << "\t\t\t\tAccount#: " << temp->accountNumber << endl;
cout << "\t\t\t\tCash: " << temp->cashAmount << endl;
cout << "\t\t\t\tTransaction Type: " << flag << endl;
cout << "\t\t\t\t----------" << endl;
cout << "\t\t\t\t Press 'Y' to confirm, or 'N' to exit" << endl;
cout << "\t\t\t\t ", cin >> confirmation;
temp->next = NULL;
if (confirmation == 'y' || confirmation == 'Y')
{
if (isEmpty())
{
temp->prev = NULL;
front = rear = temp;
cout << "\t\t\t\t Transaction Completed." << endl;
}
else
{
temp->prev = rear;
rear->next = temp;
rear = temp;
cout << "\t\t\t\t Transaction Completed." << endl;
}
}
else if (confirmation == 'n' || confirmation == 'N')
{
temp = NULL;
cout << "\t\t\t\t Transaction not Completed." << endl;
}
else
{
cout << "\t\t\t\t ERROR ERROR ERROR!!! Wrong input entered, transaction failed!" << endl;
temp = NULL;
}
cout << "\t\t\t\t Press any key to return to Bank Menu" << endl;
_getch();
}
void dequeue()
{
withdrawDepositNode *temp = front;
if (isEmpty())
{
cout << "\t\t\t\t Withdraw/Deposit Queue is empty, nothing left to process" << endl;
cout << "\t\t\t\t Press any key to return to Bank Menu" << endl;
_getch();
return;
}
else if (front == rear)
{
cout << "\t\t\t\t----------" << endl;
cout << "\t\t\t\t " << temp->accountNumber << endl;
cout << "\t\t\t\t " << temp->cashAmount << endl;
cout << "\t\t\t\t----------" << endl;
cout << "\t\t\t\t Transaction has been done." << endl;
front = rear = NULL;
}
else
{
front = front->next;
cout << "\t\t\t\t----------" << endl;
cout << "\t\t\t\t " << temp->accountNumber << endl;
cout << "\t\t\t\t " << temp->cashAmount << endl;
cout << "\t\t\t\t----------" << endl;
cout << "\t\t\t\t Transaction has been done." << endl;
}
delete temp;
cout << "\t\t\t\t Press any key to return to Bank Menu" << endl;
_getch();
}
void displayWithdrawDepositQueue()
{
withdrawDepositNode *temp = front;
if (isEmpty())
{
cout << "\t\t\t\t Withdraw/Deposit Payment Queue is empty" << endl;
cout << "\t\t\t\t Press any key to return to Bank Menu" << endl;
_getch();
return;
}
int count = 0;
while (temp != NULL)
{
cout << "\t\t\t\t--------------- #" << count++ << " ---------------" << endl;
cout << "\t\t\t\t " << temp->accountNumber << endl;
cout << "\t\t\t\t " << temp->cashAmount << endl;
cout << "\t\t\t\t Withdraw =" << temp->withdrawCash << endl;
cout << "\t\t\t\t Deposit =" << temp->depositCash << endl;
cout << "\t\t\t\t--------------- #" << count++ << " ---------------" << endl << endl;
temp = temp->next;
}
cout << "\t\t\t\t Press any key to return to Bank Menu" << endl;
_getch();
}
};