-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsUtil.h
274 lines (206 loc) · 5.79 KB
/
clsUtil.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#pragma once
#include <iostream>
#include <string>
#include "clsDate.h"
using namespace std;
class clsUtil
{
public:
enum enCharType {
SamallLetter = 1, CapitalLetter = 2,
Digit = 3, MixChars = 4, SpecialCharacter = 5
};
static void Srand()
{
//Seeds the random number generator in C++, called only once
srand((unsigned)time(NULL));
}
static int RandomNumber(int From, int To)
{
//Function to generate a random number
int randNum = rand() % (To - From + 1) + From;
return randNum;
}
static char GetRandomCharacter(enCharType CharType)
{
//updated this method to accept mixchars
if (CharType == MixChars)
{
//Capital/Samll/Digits only
CharType = (enCharType)RandomNumber(1, 3);
}
switch (CharType)
{
case enCharType::SamallLetter:
{
return char(RandomNumber(97, 122));
break;
}
case enCharType::CapitalLetter:
{
return char(RandomNumber(65, 90));
break;
}
case enCharType::SpecialCharacter:
{
return char(RandomNumber(33, 47));
break;
}
case enCharType::Digit:
{
return char(RandomNumber(48, 57));
break;
}
defualt:
{
return char(RandomNumber(65, 90));
break;
}
}
}
static string GenerateWord(enCharType CharType, short Length)
{
string Word;
for (int i = 1; i <= Length; i++)
{
Word = Word + GetRandomCharacter(CharType);
}
return Word;
}
static string GenerateKey(enCharType CharType = CapitalLetter)
{
string Key = "";
Key = GenerateWord(CharType, 4) + "-";
Key = Key + GenerateWord(CharType, 4) + "-";
Key = Key + GenerateWord(CharType, 4) + "-";
Key = Key + GenerateWord(CharType, 4);
return Key;
}
static void GenerateKeys(short NumberOfKeys, enCharType CharType)
{
for (int i = 1; i <= NumberOfKeys; i++)
{
cout << "Key [" << i << "] : ";
cout << GenerateKey(CharType) << endl;
}
}
static void FillArrayWithRandomNumbers(int arr[100], int arrLength, int From, int To)
{
for (int i = 0; i < arrLength; i++)
arr[i] = RandomNumber(From, To);
}
static void FillArrayWithRandomWords(string arr[100], int arrLength, enCharType CharType, short Wordlength)
{
for (int i = 0; i < arrLength; i++)
arr[i] = GenerateWord(CharType, Wordlength);
}
static void FillArrayWithRandomKeys(string arr[100], int arrLength, enCharType CharType)
{
for (int i = 0; i < arrLength; i++)
arr[i] = GenerateKey(CharType);
}
static void Swap(int& A, int& B)
{
int Temp;
Temp = A;
A = B;
B = Temp;
}
static void Swap(double& A, double& B)
{
double Temp;
Temp = A;
A = B;
B = Temp;
}
static void Swap(bool& A, bool& B)
{
bool Temp;
Temp = A;
A = B;
B = Temp;
}
static void Swap(char& A, char& B)
{
char Temp;
Temp = A;
A = B;
B = Temp;
}
static void Swap(string& A, string& B)
{
string Temp;
Temp = A;
A = B;
B = Temp;
}
static void Swap(clsDate& A, clsDate& B)
{
clsDate::SwapDates(A, B);
}
static void ShuffleArray(int arr[100], int arrLength)
{
for (int i = 0; i < arrLength; i++)
{
Swap(arr[RandomNumber(1, arrLength) - 1], arr[RandomNumber(1, arrLength) - 1]);
}
}
static void ShuffleArray(string arr[100], int arrLength)
{
for (int i = 0; i < arrLength; i++)
{
Swap(arr[RandomNumber(1, arrLength) - 1], arr[RandomNumber(1, arrLength) - 1]);
}
}
static string Tabs(short NumberOfTabs)
{
string t = "";
for (int i = 1; i < NumberOfTabs; i++)
{
t = t + "\t";
cout << t;
}
return t;
}
static string EncryptText(string Text, short EncryptionKey)
{
for (int i = 0; i <= Text.length(); i++)
{
Text[i] = char((int)Text[i] + EncryptionKey);
}
return Text;
}
static string DecryptText(string Text, short EncryptionKey)
{
for (int i = 0; i <= Text.length(); i++)
{
Text[i] = char((int)Text[i] - EncryptionKey);
}
return Text;
}
static string NumberToText(int Num) {
string StrNum = "";
string StrNums[]{ "","One","Two","Three","Four","Five","Six"
,"Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty" };
string StrTens[] = { "","","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninty" };
if (Num <= 20)
{
return StrNums[Num];
}
else if (Num < 100) {
return StrTens[Num / 10] + " " + NumberToText(Num % 10);
}
else if (Num < 1000) {
return StrNums[Num / 100] + " Hundred " + NumberToText(Num % 100);
}
else if (Num < 1000000) {
return NumberToText(Num / 1000) + " Thousand " + NumberToText(Num % 1000);
}
else if (Num < 1000000000) {
return NumberToText(Num / 1000000) + " Million " + NumberToText(Num % 1000000);
}
else if (Num < 1000000000000) {
return NumberToText(Num / 1000000000) + " Billion " + NumberToText(Num % 1000000000);
}
}
};