-
Notifications
You must be signed in to change notification settings - Fork 12
/
DinerMenu.h
65 lines (59 loc) · 1.77 KB
/
DinerMenu.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
#ifndef DINER_MENU_H
#define DINER_MENU_H
#include "DinerMenuIterator.h"
#include "MenuItem.h"
#include <array>
#include <iostream>
#include<memory>
#include <ostream>
#include <string>
class DinerMenu {
public:
DinerMenu();
std::string getMenuDescription() const { return menuDesciption; }
void addItem(std::string_view, std::string_view, bool, double);
std::unique_ptr<Iterator<MenuItem>> createIterator() {
return std::make_unique<DinerMenuIterator>(menuItems); }
private:
static constexpr std::size_t MAX_ITEMS = 6;
std::size_t numberOfItems = 0;
std::array<MenuItem, MAX_ITEMS> menuItems; // NOTE: MenuItem must have a default constructor
std::string menuDesciption = "Objectville Diner Menu";
};
inline
DinerMenu::DinerMenu()
{
addItem("Vegetarian BLT",
"(Fakin') Bacon with lettuce & tomato on whole wheat", true, 2.99);
addItem("BLT",
"Bacon with lettuce & tomato on whole wheat", false, 2.99);
addItem("Soup of the day",
"Soup of the day, with a side of potato salad", false, 3.29);
addItem("Hotdog",
"A hot dog, with sauerkraut, relish, onions, topped with cheese",
false, 3.05);
addItem("Steamed Veggies and Brown Rice",
"Steamed vegetables over brown rice", true, 3.99);
addItem("Pasta",
"Spaghetti with Marinara Sauce, and a slice of sourdough bread",
true, 3.89);
}
inline
void
DinerMenu::addItem(std::string_view name, std::string_view desciption,
bool vegitarian, double price)
{
auto menuItem = MenuItem(name, desciption, vegitarian, price);
if (numberOfItems >= MAX_ITEMS)
std::cerr << "Sorry, menu is full! Can't add item to men\n";
else
menuItems[numberOfItems++] = menuItem;
}
inline
std::ostream&
operator<<(std::ostream &os, const DinerMenu &menu)
{
os << menu.getMenuDescription();
return os;
}
#endif /* DINER_MENU_H */