This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomNameGenerator.cpp
235 lines (228 loc) · 6.45 KB
/
RandomNameGenerator.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
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
#define _CRT_SECURE_NO_WARNINGS //Disables the security warning for strcat
#include <iostream>
#include <conio.h>
#include <cstdlib> //Standard cpp library
#include <time.h> //Needed for random generation
using namespace std;
//Declare the function up here so that we can use it
// note that it does not return a value, rather it
// edits the character passed to it by reference
void NameGenFirstName(char *Name);
void NameGenLastName(char *Name);
//Little utility function to make getting char input easier...
char get_Char(void);
char syllables[][4]{ // Japanese syllables 2 - 105
"", "a", "i", "u", "e", "o",
"ka", "ki", "ku", "ke", "ko",
"sa", "shi", "su", "se", "so",
"ta", "chi", "tsu", "te", "to",
"na", "ni", "nu", "ne", "no",
"ha", "hi", "fu", "he", "ho",
"ma", "mi", "mu", "me", "mo",
"ra", "ri", "ru", "re", "ro",
"ga", "gi", "gu", "ge", "go",
"za", "ji", "zu", "ze", "zo",
"da", "xji", "du", "de", "do",
"ba", "bi", "bu", "be", "bo",
"pa", "pi", "pu", "pe", "po",
"ya", "yu", "yo", "wa", "wo",
"kya", "kyu","kyo", "sha", "shu","sho",
"cha", "chu","cho", "nya", "nyu","nyo",
"hya", "hyu","hyo", "mya", "myu","myo",
"rya", "ryu","ryo", "gya", "gyu","gyo",
"ja", "ju","jo", "bya", "byu","byo",
"pya", "pyu", "pyo", "n"
};
int lengthOfFirstName = 2;
int lengthOfLastName = 2;
int main()
{
char Name1[30]; //Used to hold our character's name
char Name2[30];
char cIn; //Used to get user answers to prompts.
srand((long)time(NULL)); //Seed the randum number generator...
do
{
printf("Choose a length for the First Name (2-5 0 for Random): "); cin >> lengthOfFirstName;
printf("Choose a length for the Last Name (2-5 0 for Random): "); cin >> lengthOfLastName;
NameGenFirstName(Name1);
NameGenLastName(Name2);
printf("\nFirst Name: %s", Name1);
printf("\nLast Name: %s\n\n", Name2);
puts("Would you like to generate another (Y,N): ");
cIn = get_Char();
} while (cIn != 'n' && cIn != 'N');
}
//Utility function for input
//The return type is void because we use a pointer to the array holding
// the characters of the name.
char get_Char(void)
{
char cIn;
while ((cIn = getchar()) < 27); //Ignore anything less then ESC
return cIn;
}
void NameGenFirstName(char* Name)
{
int iRandom = rand() % 100 +1;
if (lengthOfFirstName == 0) {
if (iRandom <= 25)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (iRandom <= 50)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (iRandom <= 75)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (iRandom <= 100)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
}
else if (lengthOfFirstName <= 2)
{
Name[0] = 0; //Initialize the string to "" (zero length string)
strcat(Name, syllables[rand() % 105 + 1]); //add the first syllable
strcat(Name, syllables[rand() % 105 + 1]); //add the second syllable
Name[0] = toupper(Name[0]); //Make the first letter capital...
return;
}
else if (lengthOfFirstName == 3)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (lengthOfFirstName == 4)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (lengthOfFirstName >= 5)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
}
void NameGenLastName(char* Name)
{
int iRandom = rand() % 100 + 1;
if (NameGenLastName == 0) {
if (iRandom <= 25)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (iRandom <= 50)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (iRandom <= 75)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (iRandom <= 100)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
}
else if (lengthOfLastName <= 2)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (lengthOfLastName == 3)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (lengthOfLastName == 4)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
else if (lengthOfLastName >= 5)
{
Name[0] = 0;
strcat(Name, syllables[rand() % 105 +1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
strcat(Name, syllables[rand() % 105 + 1]);
Name[0] = toupper(Name[0]);
return;
}
}