-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequenceDriver.cpp
More file actions
210 lines (168 loc) · 5.49 KB
/
SequenceDriver.cpp
File metadata and controls
210 lines (168 loc) · 5.49 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/***************************************************************************************************
CSC 326 Information Structures
Lab #1B
Sequence
Student: Maria Romanova
***************************************************************************************************/
#include <iostream>
#include <cmath>
#include "Sequence.h"
#include "ErrorMessages.h"
#include "Shell.h"
using namespace std;
/* ----------------------------------------------------------------------------------------------
NOTE: This program could work with different data types: double, float, int, char, string
To change data type make changes in two following lines of code
double: #define _DOUBLE_
float: #define _FLOAT_
int: #define _INT_
char: #define _CHAR_
string: #define _CHAR_SET_
-----------------------------------------------------------------------------------------------*/
#define _CHAR_SET_
#define CAPACITY 10
int main()
{
#if defined _DOUBLE_
double entry; // item for enter by user
Sequence<double> s1(CAPACITY); // to create sequence
Shell<double> shell; // to format output
const double INVALID_VALUE = NAN;
const string ITEM_TYPE = "REAL NUMBERS";
#elif defined _FLOAT_
float entry; // item for enter by user
Sequence<float> s1(CAPACITY); // to create sequence
Shell<float> shell; // to format output
const float INVALID_VALUE = NAN;
const string ITEM_TYPE = "REAL NUMBERS";
#elif defined _INT_
int entry; // item for enter by user
Sequence<int> s1(CAPACITY); // to create sequence
Shell<int> shell; // to format output
const int INVALID_VALUE = INT_MIN;
const string ITEM_TYPE = "INTEGER NUMBERS";
#elif defined _CHAR_SET_
string entry; // item for enter by user
Sequence<string> s1(CAPACITY); // to create sequence
Shell<string> shell; // to format output
const string INVALID_VALUE = "\0";
const string ITEM_TYPE = "CHARACTER SETS (eng keyboard)";
#elif defined _CHAR_
char entry; // item for enter by user
Sequence<char> s1(CAPACITY); // to create sequence
Shell<char> shell; // to format output
const char INVALID_VALUE = '\0';
const string ITEM_TYPE = "SINGLE CHARACTERS";
#endif
shell.displayHeader(ITEM_TYPE); // comment for user about program
// Choice to fill in the sequence with multiple items -----------------------------------------------
char ans;
cout << " Would you like to create your sequence by entering multiple items? (y/n): ";
cin >> ans;
if (ans == 'y' || ans == 'Y')
{
shell.fill_range(s1);
}
else
cout << "\n Please start entering items one by one with #4 INSERT or #5 ATTACH commands.\n\n";
// End Choice to fill in the sequence with multiple items--------------------------------------------
shell.menu(); // display menu
shell.display(s1);
int userChoice = -1;
while (userChoice != 11)
{
userChoice = -1; // assign invalid value in order to avoid input errors
entry = INVALID_VALUE;
cin.clear(); // clear cin buffer in order to avoid input errors
cin.ignore(INT_MAX, '\n');
shell.changeTextColor(8); // dark_grey text color
cout << "\n\t command #";
cin >> userChoice;
shell.changeTextColor(); // light_gray text color (console default)
// Work with menu commands
switch (userChoice)
{
case 0: // 0 - FIRST
s1.first();
shell.display(s1);
break;
case 1: // 1 - LAST
s1.last();
shell.display(s1);
break;
case 2: // 2 - NEXT = current_index + 1
if (s1.getCurrentIndex() < s1.size() - 1)
s1.next();
else if (s1.size() > 0)
shell.errorMessage(NO_NEXT);
shell.display(s1);
break;
case 3: // 3 - PREVIOUS = current_index - 1
if (s1.getCurrentIndex() > 0)
s1.previous();
else if (s1.size() > 0)
shell.errorMessage(NO_PREV);
shell.display(s1);
break;
case 4: // 4 - INSERT BEFORE CURRENT ITEM
cout << "\t enter value: ";
cin >> entry;
if (entry != INVALID_VALUE)
{
s1.insert(entry);
shell.display(s1);
}
else
shell.errorMessage(INVALID_ENTRY);
break;
case 5: // 5 - ATTACH/INSERT AFTER CURRENT ITEM
cout << "\t enter value: ";
cin >> entry;
if (entry != INVALID_VALUE)
{
s1.attach(entry);
shell.display(s1);
}
else
shell.errorMessage(INVALID_ENTRY);
break;
case 6: // 6 - REMOVE CURRENT ITEM
if (s1.current() != INVALID_VALUE)
{
cout << "\n\t The item '" << s1.current() << "' has been removed.\n";
s1.remove_current();
shell.display(s1);
}
else
shell.errorMessage(NOTHING_TO_REMOVE);
break;
case 7: // 7 - SIZE
cout << "\n\t number of items = " << s1.size() << endl;
break;
case 8: // 8- DISPLAY CURRENT ITEM
if (s1.current() != INVALID_VALUE)
{
cout << "\n\t current index = " << s1.getCurrentIndex()
<< ", current item '" << s1.current() << "'\n";
}
else
shell.errorMessage(NO_CURRENT);
break;
case 9: // 9 - DISPLAY SEQUENCE
shell.display(s1);
break;
case 10: // 10 - DISPLAY MENU
shell.menu();
break;
case 11: // 11 - EXIT
break;
default:
shell.errorMessage(WRONG_COMMAND);
break;
}// End switch
}// End while
// pause screen
cout << "\n\n\t";
system("pause");
return 0;
} // End main()