forked from raydelto/shopping_list_itla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cpp
121 lines (103 loc) · 1.63 KB
/
Menu.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Menu.cpp
*
* Created on: May 22, 2016
* Author: raydelto
*/
#include "Menu.h"
#include "List.h"
#include "Element.h"
#include <iostream>
#include <cstdlib>
using namespace std;
List* list = new List();
Menu::Menu()
{
}
void Menu::clearScreen()
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
void Menu::pause()
{
#ifdef _WIN32
system("pause");
#else
system("read -n1 -r -p \"Press any key to continue...\" key");
#endif
}
bool Menu::validate(int option)
{
if(option >= 1 && option <= 4)
{
return true;
}else
{
cout << "Please pick an option between 1 and 4"<< endl;
pause();
return false;
}
}
void Menu::routeAction(int option)
{
switch(option)
{
case 1:
listItems();
break;
case 2:
addItems();
break;
case 3:
removeItems();
break;
case 4:
cout << "Thanks for using our software, good bye!" << endl;
}
pause();
}
void Menu::listItems()
{
Element* i = list -> getFirst();
while (i != NULL)
{
cout << i -> getName() << endl;
i = i -> getNext();
}
}
void Menu::addItems()
{
string name;
cout << "Type the item Name: ";
cin >> name;
Element* item = new Element(name);
list -> add(item);
cout << "Item added successfully" << endl;
}
void Menu::removeItems()
{
cout << "sorry it cant no be remove" << endl;
}
void Menu::show()
{
int option;
do
{
clearScreen();
cout << "Shopping List" << endl;
cout << "1- List items" << endl;
cout << "2- Add Item" << endl;
cout << "3- Remove Item" << endl;
cout << "4- Exit" << endl;
cout << "Select an option => ";
cin >> option;
if(validate(option))
{
routeAction(option);
}
}while(option !=4);
}