This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiscal.cs
255 lines (230 loc) · 6 KB
/
fiscal.cs
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
using System;
using System.Globalization;
class final
{
static void Main(string[] args)
{
Console.Write("Enter First name : ");
string n1=Console.ReadLine();
string name=n1.ToUpper(new CultureInfo("en-US", false));
Console.Write("Enter surname : ");
string n2=Console.ReadLine();
string sname=n2.ToUpper(new CultureInfo("en-US", false));
int valgen=0;
string gen;
do//GENDER VALIDATION
{
Console.Write("Enter Gender M/F : ");
gen=Console.ReadLine();
if(gen =="M" | gen=="F")
{
valgen=1;
}
}while(valgen==0);
string dob;
bool res;
do
{
Console.Write("Enter DOB dd/mm/yyyy : ");
dob=Console.ReadLine();
final m=new final();
res =m.DateVal(dob);
} while (res==false);
string[,] A={{name,sname},{gen,dob}};
final s=new final();
int res2=s.Ccount(sname);
string sfiscal="";
string nfiscal="";
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
if(res2 >= 3)//surname fiscal start
{
string res3=s.sur1cal(sname);
sfiscal=res3;
}else if(res2 < 3)
{
string res3=s.sur2cal(sname);
sfiscal=res3;
}else if(sname.Length<3)
{
sfiscal=(sname+"X");
} //surname fiscal end
//name fiscal start
int res4=s.Ccount(name);
if(res4 == 3)
{
string res5=s.sur1cal(name);
nfiscal=res5;
}else if(res4>3)
{
string res5=s.n1cal(name);
nfiscal=res5;
}else if(res4<3)
{
string res5=s.sur2cal(name);
nfiscal=res5;
}else if(name.Length<3)
{
nfiscal=(name+"X");
}
//NAME FISCAL END
//DOB AND GENDER FISCAL START
string yearfiscal=dob.Substring(8,2);
string month=dob.Substring(3,2);
string mfiscal=s.getLetter(month);
string gfiscal="";
int gffiscal=0;
if(gen =="M")
{
gfiscal=dob.Substring(0,2);
}else if(gen =="F")
{
gffiscal=int.Parse(dob.Substring(0,2));
gffiscal=gffiscal+40;
gfiscal=gffiscal.ToString();
}
//DOB AND GENDER FISCAL END
Console.WriteLine("Fiscal Code is "+sfiscal+nfiscal+yearfiscal+mfiscal+gfiscal);
watch.Stop();
Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");
Console.ReadLine();
}
// METHODS
//DATE VALIDATION
bool DateVal(string tempDate)
{
DateTime fromDateValue;
var formats = new[] { "dd/MM/yyyy"};
if (DateTime.TryParseExact(tempDate, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out fromDateValue))
{
return true;
}
else
{
return false;
}
}
//CONSANANT COUNTER
int Ccount(string str)
{
int vowel=0;
int cons = 0;
int len = str.Length;
int i;
int c=0;
char[] conc=new char[len];
for(i=0; i<len; i++)
{
if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
{
vowel++;
}
else if((str[i]>='A' && str[i]<='Z'))
{
cons++;
conc[c]=(str[i]);
c++;
}
}
return cons;
}
//surname 3 or more consanants and name equal to 3 consonants
string sur1cal(string str)
{
int vowel=0;
int cons = 0;
int len = str.Length;
int i;
int c=0;
string[] conc=new string[len];
for(i=0; i<len; i++)
{
if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
{
vowel++;
}
else if((str[i]>='A' && str[i]<='Z'))
{
cons++;
conc[c]=Char.ToString(str[i]);
c++;
}
}
string sur=(conc[0]+conc[1]+conc[2]);
return sur;
}
//SURNAME AND NAME LESS THAN 3 CONCONSNTS
string sur2cal(string str)
{
int vowel=0;
int cons = 0;
int len = str.Length;
int i;
int c=0;
int f=0;
string[] conc=new string[len];
string[] conv=new string[len];
for(i=0; i<len; i++)
{
if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
{
vowel++;
conv[f]=Char.ToString(str[i]);
f++;
}
else if((str[i]>='A' && str[i]<='Z'))
{
cons++;
conc[c]=Char.ToString(str[i]);
c++;
}
}
string sur=(conc[0]+conc[1]+conv[0]);
return sur;
}
//NAME WITH MORE THAN 3 CONCANANTS
string n1cal(string str)
{
int vowel=0;
int cons = 0;
int len = str.Length;
int i;
int c=0;
string[] conc=new string[len];
for(i=0; i<len; i++)
{
if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
{
vowel++;
}
else if((str[i]>='A' && str[i]<='Z'))
{
cons++;
conc[c]=Char.ToString(str[i]);
c++;
}
}
string n1=(conc[0]+conc[2]+conc[3]);
return n1;
}
//GET letter WITH MONTH
string getLetter(string m)
{
switch (m)
{
case "01":return "A"; break;
case "02":return "B"; break;
case "03":return "C"; break;
case "04":return "D"; break;
case "05":return "E"; break;
case "06":return "H"; break;
case "07":return "L"; break;
case "08":return "M"; break;
case "09":return "P"; break;
case "10":return "R"; break;
case "11":return "S"; break;
case "12":return "T"; break;
default:return "invalid"; break;
}
}
}