/
nproj.cpp
350 lines (305 loc) · 9.34 KB
/
nproj.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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
class crim_rec
{
char name[30],sex,fname[30],addrs[25],
crime[50],bldgrp[5],dob[9];
int crim_code,reward;
void disp();
public:
void get();
void wtf();
void rtf();
void search();
void del();
void mod();
} c;
void crim_rec::get()
{
cout<<"\nEnter the Name of the criminal:";
gets(name);
cout<<"\nGender:";
cin>>sex;
cout<<"\nEnter Date of Birth:";
gets(dob);
cout<<"Enter blodd group \n A+,A-,B+,B-,AB+,AB-,O+,O-:";
gets (bldgrp);
cout<<"\nEnter father's name:";
gets(fname);
cout<<"\nEnter Address:";
gets(addrs);
cout<<"\nEnter the crime commited:";
gets(crime);
cout<<"\nEnter reward on criminal:";
cin>>reward;
}
void crim_rec::disp()
{
cout<<"The record of criminal:\n";
cout<<"\nName of criminal:"<name;
cout<<"\nGender:"<<sex;
cout<<"\nDOB:"<<dob;
cout<<"\nBlood Group:"<<bldgrp;
cout<<"\nFather's name:"<<fname;
cout<<"\nAddress:"<<addrs;
cout<<"\nCrime:"<<crime;
cout<<"\nReward:"<<reward;
}
void crim_rec::wtf()
{
ofstream ofile;
ofile.open("CBI.dat",ios::app|ios::binary);
get();
ofile.write((char*)&c,sizeof(c));
ofile.close();
}
void crim_rec::rtf()
{
ifstream ifile;
ifile.open("CBI.dat",ios::binary|ios::in);
ifile.seekg(0,ios::beg);
while(ifile)
{
ifile.read((char*)&c,sizeof(c));
if(ifile.eof())
break;
c.disp();
}
ifile.close();
}
void crim_rec::search()
{
char m[20];
ifstream ifile("CBI.dat",ios::in|ios::in);
cout<<"Enter the name of criminal to be searched:";
gets(m);
ifile.seekg(0,ios::beg);
ifile.read((char*)&c,sizeof(c));
while(ifile)
{
if(strcmpi(m,c.name)==0)
c.disp();
ifile.read((char*)&c,sizeof(c));
}
ifile.close();
}
void crim_rec::del()
{
char b[20];
ifstream ifile;
ifile.open("CBI.dat",ios::in|ios::binary);
ofstream ofile;
ofile.open("new.dat",ios::app|ios::binary);
cout<<"Enter the name of the criminal whose record you want to delete:";
gets(b);
ifile.seekg(0,ios::beg);
ifile.read((char*)&c,sizeof(c));
while(ifile)
{
if(strcmpi(b,c.name)!=0)
ofile.write((char*)&c,sizeof(c));
ifile.read((char*)&c,sizeof(c));
}
ifile.close();
ofile.close();
remove("CBI.dat");
rename("new.dat","CBI.dat");
cout<<"\nRecord Deleted Successfully:";
}
void crim_rec::mod()
{
char d[20];
int p,a;
cout<<"\nEnter the name of the criminal whose record you want to modify\n";
gets(d);
fstream f;
crim_rec newrec;
f.open("CBI.dat",ios::in|ios::out|ios::binary);
f.seekg(0,ios::beg);
while(!f.eof())
{
f.read((char*)&c,sizeof(c));
if(!strcmpi(d,c.name))
{
cout<<"\nPress 1 to change name:";
cout<<"\nPress 2 to change gender:";
cout<<"\nPress 3 to change date of birth:";
cout<<"\nPress 4 to change blood group:";
cout<<"\nPress 5 to change father's name:";
cout<<"\nPress 6 to change address:";
cout<<"\nPress 7 to change crime commited:";
cout<<"\nPress 8 to change reward on criminal:\n";
cin>>p;
switch(p)
{
case 1:
gets(c.name);
break;
case 2:
cin>>c.sex;
break;
case 3:
gets(c.dob);
break;
case 4:
gets(c.bldgrp);
break;
case 5:
gets(c.fname);
break;
case 6:
gets(c.addrs);
break;
case 7:
gets(c.crime);
break;
case 8:
cin>>c.reward;
break;
}
f.seekp(f.tellg()-sizeof(c));
}
}
cout<<"\nRecord Modified Successfully:";
f.close();
}
void passwd(char*ar,int max)
{
char v;
int x=0;
while(1)
{
v=getch();
if(v==13)
{
ar[x]='\0';
break;
}
if(v==8 && x!=0)
{
cout<<"\b \b";
if(x<=max && x>0)
x--;
}
else
if(x<max && v!=8)
{
cout<<"*";
ar[x]=v;
x++;
}
}
}
void main()
{
int ch;
char choice;
char u[15],ps[11];
cout<<"*****************************************************:";
cout<<"\n\n\t\t*********PROJECT ON CRIMINAL INVESTIGATION:**********:";
cout<<"\n\n*********************************************************:";
cout<<"\n\n\t\t\t\t\tCompiled and Presented by:";
cout<<"\n\n\t\t\t\t\tShreyash Kashyap-XII-C:";
cout<<"\n\nPress any key to continue......";
getch();
do
{
clrscr();
cout<<"\t Central Bureau of Investigation:";
cout<<"\n*******************************:";
cout<<"\n\n* 1.View criminal details *";
cout<<"\n\n* 2.Add new criminal details *";
cout<<"\n\n* 3.Search a criminal record *";
cout<<"\n\n* 4.Delete a criminal record *";
cout<<"\n\n* 5.Modify a criminal record: *";
cout<<"\n\n Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the Username:";
gets(u);
cout<<"Enter the password :";
passwd(ps,10);
if(strcmpi(u,"Shreyas")==0)
{
if(strcmpi(ps,"shreyas")==0)
cout<<"\n Access Granted:\n";
}
else if(strcmpi(u,"Jamie")==0)
{ if(strcmpi(ps,"jamie")==0)
cout<<"\n Access Granted:\n";
}
else
{ cout<<"\n Access Denied:\n";
getch();
exit(0);
}
getch();
c.rtf();
break;
case 2:
cout<<"Enter the Username:";
gets(u);
cout<<"Enter the password :";
passwd(ps,10);
if(strcmpi(u,"Shreyas")==0)
{
if(strcmpi(ps,"shreyas")==0)
cout<<"\n Access Granted:\n";
}
else if(strcmpi(u,"Jamie")==0)
{ if(strcmpi(ps,"jamie")==0)
cout<<"\n Access Granted:\n";
}
else
{ cout<<"\n Access Denied:\n";
getch();
exit(0);
}
getch();
c.wtf();
break;
case 3:
c.search();
break;
case 4:
c.del();
break;
case 5:
cout<<"Enter the Username:";
gets(u);
cout<<"Enter the password :";
passwd(ps,10);
if(strcmpi(u,"Shreyas")==0)
{
if(strcmpi(ps,"shreyas")==0)
cout<<"\n Access Granted:\n";
}
else if(strcmpi(u,"Jamie")==0)
{ if(strcmpi(ps,"jamie")==0)
cout<<"\n Access Granted:\n";
}
else
{ cout<<"\n Access Denied:\n";
getch();
exit(0);
}
getch();
c.mod();
break;
default:
{
cout<<"\nerror!";
}
break;
}
cout<<"\nContinue? (y/n)\n";
cin>>choice;
}while(choice=='y'||choice=='Y');
cout<<"\nGood bye";
}