-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountFile.cpp
More file actions
54 lines (43 loc) · 1.12 KB
/
AccountFile.cpp
File metadata and controls
54 lines (43 loc) · 1.12 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
#include "AccountFile.h"
using namespace std;
bool AccountFile::addAccount(Account account)
{
for (int i = 0; i < this->arr.size(); i++)
{
if (this->arr[i].getUsername() == account.getUsername())
{
cout << "Username is already taken. Choose another username." << endl;
return false;
}
}
this->arr.push_back(account);
return true;
}
bool AccountFile::logIn(Account account)
{
for (int i = 0; i < this->arr.size(); i++) {
if (this->arr[i] == account)
{
this->currentAccount = account;
cout << "You have logged in successfully." << endl;
return true;
}
}
cout << "There is no account with this username and password. Try again or create a new account." << endl;
return false;
}
void AccountFile::logOut()
{
this->currentAccount.setUsername("Guest");
this->currentAccount.setPassword("");
}
void AccountFile::printAccount() const {
cout <<"You are currently logged in as: "<< this->currentAccount.getUsername() << endl;
}
void AccountFile::printAllAccounts() const
{
for (int i = 0; i < this->arr.size(); i++)
{
cout << this->arr[i].getUsername() << ", " << this->arr[i].getPassword();
}
}