-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.cpp
106 lines (91 loc) · 1.77 KB
/
Account.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
#include "Account.h"
Account::Account()
{
this->setUsername("Guest");
this->setPassword("");
}
Account::Account(string username, string password)
{
this->setUsername(username);
this->setPassword(password);
}
bool operator==(Account first, Account second)
{
if (first.username == second.username && first.password == second.password)
{
return true;
}
return false;
}
void Account::setUsername(string u)
{
this->username = u;
}
void Account::setPassword(string p)
{
this->password = p;
}
string Account::getUsername() const
{
return this->username;
}
string Account::getPassword() const
{
return this->password;
}
const Cart& Account::getCart() const
{
return this->cart;
}
const Order& Account::getOrder() const
{
return this->currentOrder;
}
void Account::setAddress(const Address& address)
{
this->address = address;
}
Address Account::getAddress() const
{
return this->address;
}
void Account::addProductToCart(Product product)
{
this->cart.addProduct(product);
}
void Account::checkOut()
{
double total = 0;
cout << "You have ordered: ";
for (int i = 0; i < this->getCart().getProductsCount(); i++)
{
cout << this->getCart().getArray()[i].getName() << ", ";
total += this->getCart().getArray()[i].getPrice();
}
cout << endl;
cout << "For a total of " << total << endl;
this->address.print();
while (true)
{
int toDo;
cout << "To confirm the order press 1. Press 2 to empty your cart. Press 3 to change your address" << endl;
cin >> toDo;
if (toDo == 1)
{
this->currentOrder.setSum(total);
this->currentOrder.generateId();
this->currentOrder.writeOrderToLog();
break;
}
if (toDo == 2)
{
this->cart.emptyArr();
total = 0;
/*this->cart.printContents();*/
}
if (toDo == 3)
{
this->address.inputAddress();
}
}
}