-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutilities.cpp
201 lines (178 loc) · 3.81 KB
/
utilities.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
#ifndef utilities_cpp
#define utilities_cpp
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ulli;
namespace Utilities{
struct my_exception
{
// error message
string message;
// assigning message to error
my_exception(string error): message(error){};
// function to get what type of error it is
string what()
{
return message;
}
};
bool check_email_iitj(char input[]){
char *ptr;
ptr= strstr(input,"@iitj.ac.in"); //searches input array for "@iitj.ac.in" string
if(ptr)
{
return true;
}
return false;
}
bool verify_email(char input[]){
string empty_email;
if(check_email_iitj(input)==false)
{
cout<<"> this email does not belong to iitj!\n";
return false;
}
return true;
}
string get_email()
{
string email;
getline(cin,email);
int x = 100; //[email protected]
char input[x]; //array to hold input
copy(email.begin(),email.end(),input);
input[email.length()]='\0';
// convert(email,input);
string first_part;
int second_part_length=0;
int count_at=0,count_dot=0;
for(char temp: email)
{
if(temp=='@')
count_at++;
if(count_at==0)
first_part.push_back(temp);
if(count_at!=0)
{
second_part_length++;
if(temp=='.')
count_dot++;
}
}
string empty;
if(second_part_length>29 || count_dot==0||count_at!=1)
{
cout<<"> not a valid email\n";
return empty;
}
if(verify_email(input)==false)
{
return empty;
}
return first_part;
}
char encrypt(char str[])
{
for(int i=0;str[i]!='\0';i++)
str[i]=str[i]-27;
}
void convert(string str,char data[])
{
copy(str.begin(),str.end(),data);
data[str.size()]='\0';
}
string valid_phone_size(string phone_number)
{
string empty;
if(phone_number.size()!=10)
{
cout<<"> Phone number be exactly of 10 digits\n";
return empty;
}
return phone_number;
}
string all_digits(string phone_number)
{
string empty;
for(char ch: phone_number)
{
if(!(ch>='0' && ch<='9'))
{
cout<<"> It must only be a digit";
return empty;
}
}
return phone_number;
}
string ulli_to_string(ulli number)
{
ulli factor=10;
while(number/factor>0)
{
factor=factor*(ulli)10;
}
factor=factor/(ulli)10;
string answer;
while(factor>0)
{
answer.push_back(number/factor+'0');
number=number%factor;
factor=factor/10;
}
return answer;
}
void loading(int x)
{
for(int i=0;i<=100;i=i+2)
{
cout<<"\r> Loading"; //sort of overwrite
int j;
for(j=0;j<=100;j=j+4)
{
if(j<=i)
cout<<" .";
else
cout<<" ";
}
cout<<" ";
cout<<i<<"%";
for(int j=0;j<x*1000000;j++);
cout.flush();
}
cout<<"\n";
}
void logging_out(int x)
{
for(int i=0;i<=100;i=i+2)
{
cout<<"\r> Logging out"; //sort of overwrite
int j;
for(j=0;j<=100;j=j+4)
{
if(j<=i)
cout<<" .";
else
cout<<" ";
}
cout<<" ";
cout<<i<<"%";
for(int j=0;j<x*1000000;j++);
cout.flush();
}
cout<<"\n";
}
string generate_otp()
{
random_device random_device;
mt19937 random_engine(random_device());
uniform_int_distribution<int> distribution_1_100(0,9);
string otp;
srand(time(NULL));
for(int i=0;i<6;i++)
{
otp.push_back(distribution_1_100(random_engine)+'0');
}
return otp;
}
};
#endif