-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
147 lines (129 loc) · 4.66 KB
/
Menu.cpp
File metadata and controls
147 lines (129 loc) · 4.66 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// ==========================================
// Menu.cpp - Defines behavior for Menu class
//
// Version: 1.0.0
// Date: 6/3/17
// By: Colten Sullivent
// ==========================================
// ===================
#include <iostream>
#include "stdafx.h"
// ===================
// ====================
using namespace std;
// ====================
// ============================
// Constructors and destructors
// ============================
Menu::Menu() {
userMenuSelection = Quit;
} // constructor
Menu::~Menu() {
cout << "Destructor ~Menu invoked" << endl;
} // destructor
// ===============
// ======================
// Accessors and mutators
// ======================
MenuChoices Menu::Get() {
return userMenuSelection;
} // accessor
void Menu::set(MenuChoices newValue) {
userMenuSelection = newValue;
} // mutator
// ============
// ==================
// function Display()
// ======================
void Menu::Display() {
cout << "============================================" << endl;
cout << "1. InitializeList 2. DestroyList " << endl;
cout << "3. InsertFirst 4. InsertLast 5. Insert" << endl;
cout << "6. DeleteFirst 7. DeleteLast 8. Delete" << endl;
cout << "9. Print 10. ReversePrint " << endl;
cout << "11. Quit " << endl;
cout << "============================================" << endl;
} // function Display()
// =======================
// ====================
// function QueryUser()
// ========================
void Menu::QueryUser() {
int input;
cout << "Enter Menu Selection: ";
cin >> input;
// ===============================
if (input < 12 && input > -1) {
userMenuSelection = (MenuChoices)(input - 1);
} else {
cout << "Unknown. Quitting." << endl;
userMenuSelection = Quit;
} // if/else
// ============
} // function QueryUser
// =======================
// ===================
// function Continue()
// =======================
bool Menu::Continue() {
return userMenuSelection != Quit;
} // function Continue()
// ========================
// ==========================================
// function ProcessCommand(SinglyLinkedList&)
// ===================================================
void Menu::ProcessCommand(SinglyLinkedList &list) {
int integerValue;
int location;
// ================================
if (userMenuSelection != Quit) {
// ============================
switch (userMenuSelection) {
case InitializeList:
list.InitializeList();
break;
case DestroyList:
list.DestroyList();
break;
case InsertFirst:
cout << "Enter a value to add to the beginning of the list. ";
cin >> integerValue;
list.InsertFirst(integerValue);
break;
case InsertLast:
cout << "Enter a value to add to the end of the list. ";
cin >> integerValue;
list.InsertLast(integerValue);
break;
case Insert:
cout << "Enter a value to insert into the list. ";
cin >> integerValue;
cout << "Enter a node location for insertion. ";
cin >> location;
list.Insert(integerValue, location);
break;
case DeleteFirst:
list.DeleteFirst();
break;
case DeleteLast:
list.DeleteLast();
break;
case Delete:
cout << "Enter a node location for deletion. ";
cin >> location;
list.Delete(location);
break;
case Print:
list.Print();
break;
case ReversePrint:
list.ReversePrint(list.GetFirst());
break;
default:
break;
} // switch
// ===========
} // if
// =======
} // function ProcessCommand(SinglyLinkedList&)
// ===============================================