-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArraysProgram.h
149 lines (111 loc) · 3.39 KB
/
ArraysProgram.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
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
#include <iostream>
#include"ListsUsingArrays.h"
using namespace std;
typedef int ChoiceType;
// Main Menu
void Menu(ARRAY_SIZE listSize)
{
cout << "====================================\n";
cout << "LIST (ARRAY) PROGRAM\n";
cout << "====================================\n";
cout << "There are currently " << ArrayCountItem(listSize) << " items in the list.\n";
cout << endl
<< endl;
cout << "====================================\n";
cout << "Options:\n";
cout << "(1). Add item to the list\n"
<< "(2). Delete Item From The list\n"
<< "(3). Locate Items in the list\n"
<< "(4). Print Items in the list\n"
<< "(5). Exit Program\n"
<< "====================================\n";
cout << endl
<< endl;
}
USER_INPUT ChoicePicker()
{
USER_INPUT Choice;
cout << "Enter the number of your choice: ";
cin >> Choice;
while ((Choice < 1) || (Choice > 5))
{
cout << "Invalid Choice! Please try again!\n"
<< "Enter the number of your choice (1-5): ";
cin >> Choice;
}
return Choice;
}
void ArrayMain()
{
ARRAY List[MAX_SIZE] = {0}, NewData, SearchData;
ARRAY_SIZE ListSize = -1, Position;
USER_INPUT Choice;
do
{
Menu(ListSize);
Choice = ChoicePicker();
switch (Choice)
{
case 1: // add an item
cout << endl
<< "Enter position: ";
cin >> Position;
while (Position < 1 || Position > ArrayCountItem(ListSize) + 1)
{
cout << endl
<< "POSITION IS INVALID... TRY AGAIN!!!";
cout << endl
<< "Enter position: ";
cin >> Position;
}
cout << endl
<< "Enter new data: ";
cin >> NewData;
ArrayAddItem(List, NewData, Position - 1, &ListSize);
break;
case 2: // delete an item
if (ArrayListEmpty(ListSize))
{
cout << endl
<< "The List is Empty!" << endl;
break;
}
else
{
cout << endl
<< "Enter position to delete: ";
cin >> Position;
while (Position < 1 || Position > ArrayCountItem(ListSize))
{
cout << endl
<< "POSITION IS INVALID... TRY AGAIN!!!";
cout << endl
<< "Enter position: ";
cin >> Position;
}
ArrayDeleteItem(List, Position - 1, &ListSize);
break;
}
case 3: // locate an item
if (ArrayListEmpty(ListSize))
{
cout << endl
<< "The List is Empty!" << endl;
break;
}
else
{
cout << "\nEnter Search Data: ";
cin >> SearchData;
ArrayLocateItem(List, SearchData, ListSize);
break;
}
case 4: // print all Items
ArrayPrintItems(List, ListSize);
break;
default:
cout << "\nTHANK YOU FOR USING THIS PROGRAM";
cout << "\nGOOD BYE!!!";
}
} while (Choice != 5);
}