-
Notifications
You must be signed in to change notification settings - Fork 1
/
UAP_ManajemenRestoran.cpp
79 lines (63 loc) · 1.73 KB
/
UAP_ManajemenRestoran.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
/* Ujian Akhir Praktikum - Structured Programming
* Restaurant Management
*
* Contributor
* 2217051004
*
*/
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
class Order {
private:
std::string name;
std::vector<std::string> listOfOrders;
void sortOrders();
public:
Order(const std::string &str, const std::initializer_list<std::string> &ls) : name(str), listOfOrders(ls) {}
void setName(const std::string &newName);
void setListOfOrders(const std::vector<std::string> &ls);
const std::string& getName();
const std::vector<std::string>& getListOfOrders();
void addOrder(const std::string &newOrder);
bool cancelOrder(const std::string &orderName);
void printOrders();
};
void Order::setName(const std::string &newName)
{
this->name = newName;
}
void Order::setListOfOrders(const std::vector<std::string> &ls)
{
this->listOfOrders = ls;
}
const std::string& Order::getName()
{
return this->name;
}
const std::vector<std::string>& Order::getListOfOrders()
{
return this->listOfOrders;
}
void Order::addOrder(const std::string &newOrder)
{
this->listOfOrders.push_back(newOrder);
}
bool Order::cancelOrder(const std::string &orderName)
{
std::vector<std::string>::iterator it = std::find(this->listOfOrders.begin(), this->listOfOrders.end(), orderName);
if (it != this->listOfOrders.end()) {
this->listOfOrders.erase(it);
return true;
}
return false;
}
void Order::printOrders()
{
std::cout << "List of orders by " << this->name << std::endl;
for (size_t i = 0, n = this->listOfOrders.size(); i < n; ++i) {
std::cout << i+1 << ". " << this->listOfOrders[i] << std::endl;
}
std::cout << std::endl;
}