Report abuse

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
/*
	Anthony Wlodarski
	ant92083@gmail.com
	Bank Account Class
*/

#include <iostream>
#include <string>
using namespace std;

class bankAccount
{
	string password;
	string firstName;
	string lastName;
	float accountBalance;

public:
	// deconstructor
	~bankAccount();
	bankAccount(string firstName, string lastName, string password, float balance); // default constructor
	// set methods
	void setPassword(string password);
	void setFirstName(string firstName);
	void setLastName(string lastName);
	void setAccountBalance(float accountBalance);
	// get methods
	float getAccountBalance() { return this->accountBalance; }
	string getAccountName() { return this->lastName + " " + this->lastName; }
	string getPassword() { return this->password; }
	// additional functions
	bool authenticate(string password);
	bool deposit(float n);
	bool withdrawal(float n);
	bool changePassword();
};

int main()
{
	bool exit = false;
	bankAccount *myAccount = new bankAccount("Anthony", "Wlodarski", "plasticpen5", 2000.00);
	int command = 0;
	float deposit, withdrawal = 0.0;

	while(!exit)
	{
		// reset the command
		command = 0;
		withdrawal = 0;
		deposit = 0;

		cout << "Please enter one of the following choices." << endl;
		cout << "1. View account balance." << endl;
		cout << "2. Make a deposit." << endl;
		cout << "3. Make a withdrawal." << endl;
		cout << "4. Change account password." << endl;
		cout << "5. Exit." << endl << endl;
		
		cin >> command;

		switch(command)
		{
		case 1:
			cout << "Your account balance is: " << myAccount->getAccountBalance() << endl;
			break;
		case 2:
			cout << "Please enter the amount you would like to deposit (xxxx.xx format please):" << endl;
			cin >> deposit;
			myAccount->deposit(deposit);
			break;
		case 3:
			cout << "Enter the amount you would like to withdraw:" << endl;
			cin >> withdrawal;
			myAccount->withdrawal(withdrawal);
			cout << "Your account balance is: " << myAccount->getAccountBalance() << endl;
			break;
		case 4:
			myAccount->changePassword();
			break;
		case 5:
			exit = true;
			break;
		default:
			cout << "You did not enter one of the above commands please try again." << endl;
		}
	}// end of while loop

	// clean up our dynamic memory allocation
	delete myAccount;

	return 0;
}

// Class function defintions
// deconstructor
bankAccount::~bankAccount() {}

bankAccount::bankAccount(std::string firstName, std::string lastName, std::string password, float balance)
{
	this->firstName = firstName;
	this->lastName = lastName;
	this->password = password;
	this->accountBalance = balance;
}

// set password
void bankAccount::setPassword(string password)
{
	this->password = password;
}
// set account firstname
void bankAccount::setFirstName(string firstName)
{
	this->firstName = firstName;
}

//
void bankAccount::setLastName(string lastName)
{
	this->lastName = lastName;
}

// set the account balance
void bankAccount::setAccountBalance(float accountBalance)
{
	this->accountBalance = accountBalance;
}

// authenticate the password
bool bankAccount::authenticate(string password)
{
	if(this->password == password)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//deposit funds into the account
bool bankAccount::deposit(float n)
{
	string password = "";
	cout << "Please enter your password: ";
	cin >> password;

	if(this->authenticate(password))
	{
		this->setAccountBalance(this->accountBalance + n);
		cout << "Your funds have been deposited succesfully." << endl;
		cout << "Your new account balance is: " << this->getAccountBalance() << endl;
		return true;
	}
	else
	{
		cout << "We could not authenticate you to the system, returning to main menu." << endl;
		return false;
	}
}

bool bankAccount::withdrawal(float n)
{
	string password = "";
	cout << "Please enter your password: ";
	cin >> password;
	if(this->authenticate(password))
	{
		if(n > this->accountBalance)
		{
			cout << "Insufficient funds, cannot withdraw " << n << " from bank account." << endl;
			return false;
		}
		else
		{
			this->setAccountBalance(this->accountBalance - n);
			cout << "Please remember to take your cash and your recepit! " << endl;
			return true;
		}
	}
	else
	{
		cout << "We could not authenticate you to the system, returning to main menu." << endl;
		return false;
	}
}

bool bankAccount::changePassword()
{
	string old, first, second;
	cout << "Please enter your old password: ";
	cin >> old;

	if(this->authenticate(old))
	{
		cout << "Please enter your new password: ";
		cin >> first;
		cout << "Please enter your new password again: ";
		cin >> second;

		if(first == second)
		{
			this->setPassword(first);
			cout << "Your authentication token has been updated, returning to main menu." << endl;
			return true;
		}
		else
		{
			cout << "Authentication tokens did not match, returning you to the main menu." << endl;
			return false;
		}
	}
	else
	{
		cout << "You failed to authenticate to the system, returning to main menu." << endl;
		return false;
	}
}