#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<fstream>
#include<string.h>
#include<
> stdlib
.h>
#include<iomanip>
/*********
* STRUCTURE FOR DATE
********/
struct date
{
int d;
int m;
int y;
};
/*********
* struct for details of crime of criminals*
********/
struct court
{
char crime[20];
char act[20];
char court[20];
char state[20];
};
/*********
* structure for physical description of criminal
********/
struct descp
{
char colour[20];
char face[20];
char imark[20];
char height[20];
};
/*********
* structure for details of F.I.R
********/
struct police
{
char station[50];
char fir_no[10];
date date_arrest;
};
/*********
class CRIMINAL FOR GETTING ALL INFORMATION ABOUT
COVICT
*********/
class criminal
{
char name[20];
char sex[3];
char conno[10];
char age[4];
char address[50];
court COURT;
police POLICE;
descp des;
public:
int ncheck(char arr[]);
int s_check(char arr[]);
void input (void);
void output (void);
void delete_rec(char con_no[]);
int dcheck(char n[]);
void display();
void remove();
int menu();
void modify();
void list();
void empty();
int concheck(char b[]);
};
/*******
end of class criminal
*******/
/*******
function for checking wether input is corrrect or not
********/
int criminal::ncheck(char arr[])
{
int i=0;
while(arr[i]!='\0')
{
if(((arr[i]>64)&&(arr[i]>92))||((arr[i]&&(arr[i]<124))||(arr[i]=='.')))
{
i++;
continue;
}
else
{
cout<<"\nINCORRECT INPUT TRY AGAIN!!";
return 0;
}
}
return 1;
}
/*********
function to check wether sex is given correctly
*********/
int criminal::s_check(char a[])
{
clrscr();
if(((a[0]=='m')||(a(0)=='f')||(a[0]=='M')||(a(0)=='F')&&(a[1]=='/0')))
{
return (1);
}
else
{
cout<<"\n INCORRECT INPUT TRY AGAIN";
return(0);
}
}
/*********
* function for getting conviicts record
*********/
void criminal::input(void)
{
clrscr();
this->empty();criminal x;
int c=0;
fstream filin;
filin.open("jail.dat",ios::app|ios::binary);
while(!c)
{
cout<<"\nENTER THE CONVICT CODE:";
gets(this->conno);
c=x.concheck(this->conno);
}
c=0;
{
cout<<"\nENTER THE CONVICT NAme:";
gets(this->name);
c=ncheck(this->name);
}
c=0;
while(!c)
{
cout<<"\n ENTER SEX:";
gets(this->sex);
c=s_check(this->sex);
}
cout<<"\nENTER ADDRESS:";
gets(this->address);
cout<<"\nENTER AGE:";
gets(this->age);
clrscr();
cout<<"\n ENTER DESRIPTION:\n\n\t";
c=0;
while(!c)
{
cout<<"\n ENTER COLOUR:";
gets(this->des.colour);
}
c=0;
while(!c)
{
cout<<"\n FACE DESCRIPTION:";
gets(this->des.face);
}
cout<<"\n ENTER HEIGHT(in cm's):";
gets(this->des.height);
cout<<"\n ENTER IDENTIFICATION MARKS(if no distinguishing marks,enter NONE):";
gets(this->des.imark);
clrscr();
cout<<"ENTER:\n\n\t\t";
c=0;
while(!c)
{
cout<<"COURT (from which the prisonor convicted):";
gets(this->COURT.court);
c=ncheck(this->COURT.court);
}
c=0;
while(!c)
{
cout<<"\n\t\tSTATE:";
gets(this->COURT.state);
c=ncheck(this->COURT.state);
}
c=0;
while(!c)
{
cout<<"\n\t\tCRIME";
gets(this->COURT.crime);
c=ncheck(this->COURT.crime);
}
cout<<"n\t\t ACT (under which convicted)";
gets(this->COURT.act);
clrscr();
cout<<"\n ENTER:\n\n\t\t";
cout<<"\n COMPLETE ADRESS OF POLICE STATION:";
gets(this->POLICE.station);
cout<<"\n FIR NO(under which convict was arrested):";
gets(this->POLICE.fir_no);
cout<<"\n ENTER DATE OF ARREST(dd/mm/yy):";
c=0;
while(!c)
{
cout<<"\n\t\t\t\t\t day:";
cin>>this->POLICE.date_arrest.d;
if((this->POLICE.date_arrest.d>31)||(this->POLICE.date_arrest.d<1))
{
cout<<"\n\n THIS DATE DOES NOT EXIST";
c=0;
}
else c=1;
}
c=0;
while(!c)
{
cout<<"\n\t\t\t\t\t month:";
cin>>this->POLICE.date_arrest.m;
if((this->POLICE.date_arrest.m>12)||(this->POLICE.date_arrest.m<1))
{
cout<<"\n\n THIS MONTH DOES NOT EXIST";
c=0;continue;
}
else c=1;
}
if((this->POLICE.date_arrest.d==31)&&(this->POLICE.date_arrest.m==2)||(this->POLICE.date_arrest.m==4)||(this->POLICE.date_arrest.m==6)||(this->POLICE.date_arrest.m==9)||(this->POLICE.date_arrest.d==11))
{
cout<<"\n THIS MONTH DOES NOT HAVE 31 DAYS TRY AGAN!!";
c=0;
}
else
c=1;
}
c=0;
while(!c)
{
cout<<"\n\n\t\t\t\t year (in 4 digits):";
cin>>this->POLICE.date_arrest.y;
if(this->POLICE.date_arrest.y<=1930)||(this->POLICE.date_arrest.y<2008))
{
cout<<"\n INCORRECT INPUT\n TRY AGAIN!!\n";
c=0;
}
else
c=1;
}
char ch;
do
{
cout<<"\n DO YOU WANT TO SAVE THIS INFORMATION(enter y or n)":
cin>>ch;
if(ch=='y'||ch=='Y')
{
cout"\n\n\t RRECORD HAS BEEN SAVED";
filin.write((char*)this,sizeof(criminal));
}
else
{
if(ch!=='n')&&(ch!=='N')
{
cout"\n\n\t ENTER CORRECTLY \n\n TRY AGAIN";
}
}
}
while(((ch!=='n')&&(ch!=='N')&&(ch!=='y')&&(ch!=='Y'));
filin.close();
}
//end of input function
/*************************
function for showing criminal record
**************************/
void criminal::output()
{
clrscr();
cout<<"__ PERSAONAL RECORD OF CONVICT__:";
cout<<"\n\n CONVICT NO";
puts(conno);
cout<<"\nName:\t";
puts(this->name);
cout<<"\nsex:\t";
puts(this->sex);
cout<<"\naddress:\t";
puts(this->address);
cout<<"\ndescription:\t";
cout<<"\n1.colour:\t";
puts(this->des.colour);
cout<<"\n2.face:\t";
puts(this->des.face);
cout<<"\n3.identification mark:\t";
puts(this->des.imark);
cout<<"\n4.height:\t";
puts(this->des.height);
cout<<"\n\n\n\n\n\t\t\t\t\ press a key to continue";
getche();
clrscr();
cout<<"=====criminal record=====";
cout<<"\n1.COURT FROM WHICH WAS CONVICTED :\t";
puts(this->COURT.cour);
cout<<"\n2.STATE :\t";
puts(this->COURT.state);
cout<<"\n3.ACT UNDER WHICH CONVICTED :\t";
puts(this->COURT.act);
cout<<"\n\n\n\n\n\t\t\t\t\ press a key to continue";
getche();
clrscr();
cout<<"=====criminal record=====";
cout<<"=====police record=====";
cout<<"\n1.FIR no. :\t";
puts(this->POLICE.fir_no);
cout<<"\n2. date of arrest :\t";
puts(this->POLICE.date_arrest.d<<"/"<<POLICE.date_arrest.m<<"/"<<this->POLICE.date_arrest.y);
cout<<"\n3. police station (where fir was loddged):\t";
puts(this->POLICE.station);
cout<<"\n\n\n\n\n\t\t\t\t\ press a key to continue";
getche();
clrscr();
}//end of output function
/**********************************
function of deleting the record of a conc=vict
***********************************/
void criminal::delete_rec(char con_no[])
{
fstream filin;
filin.open("jail.dat",ios::in|ios::ate);
int q=filin.tellg();
int c=q/sizeof(criminal);
fstream temp;
temp.open("temp.dat",ios::out);
filin.seekg(0,ios::beg);
for(int i=0;i<c;i++)
{
filin.read((char*)this,sizeof(criminal));
if(strcmp(con_no,conno)!=0
temp.write((char*)this,sizeof(criminal));
}
filin.close();
temp.close();
filin.open("jail.dat",ios::in|ios::ate);
int a=filin.tellg();
int size=a/sizeof(criminal);
temp.seekg(0,ios::beg);
for(int k=0;k<size;k++)
{
temp.read((char*)this,sizeof(criminal));
filin.write((char*)this,sizeof(criminal));
}
filin.close();
temp.close();
cout<<"/n/n THE RECORD HAS BEEN DELETED">>;
}
//**************************************
//
int criminal::dcheck(char n[])
{
clrscr();
fstream file;
file.open("jail.dat",ios::in|ate|ios::binary);
int x=0;int count=0,c;
int q=file.tellg();
c=q/sizeof(criminal);
file.close();
file.open("jail.dat",ios::in|ate|ios::binary);
for(int i=0;i<c;i++)
{
file.read((char*)this,sizeof(criminal));
count++;
if(strcmp(n,conno)==0)
{
x++;
break;
}
if(x==0)
{
cout<<"/n CONVICT NOT FOUND!";
return 0;
}
else
{
return count;
}
file.close();
}
}
//********************************
//
void criminal::display()
{clrscr();
char N[10];
int rec;
int loc;
cout<<"\n ENTER THE CONVICT CODE OF CONVICT";
cout<<" WHOSE INFORMATION YOU WANT :";
gets(N)
fstream file;
rec=this->dcheck(N)
file.open("jail.dat",ios::in[ios::binary]:
if(rec!=0)
{
loc={rec-1)*size of (criminal);
file.see kg(loc)
file.read((char*)this,size of (criminal)):
this->output():
}
file.close();
}
//--------------------------------------------------------------------------
//
void criminal:: remove()
{
char no[10];int s;
cout<<"\n ENTER THE CONVICT NO.OF THE CONVICT WHOSE RECORD YOU WISH TO ":
cout<<"DELETE:";
gets(no);
s= this->dcheck(no);
if(s!=0)
this->delete_rec(no);
}
//_---------------------------------------------------------------------
//
int criminal::menu()
{int ch;
do{
clrscr();
cout<<"\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ MAIN MENU@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
cout<<"\n PRESS:\n\n";
cout<<"\n\t\t\t1. TO ADD RECORD / RECORDS";
cout<<"\n\t\t\t2.TO MODIFY RECORD/ RECORDS";
cout<<"\n\t\t\t3.TO DISPLAY RECORD";
cout<<"\n\t\t\t4.TO DELETE RECORD ";
cout<<"\n\t\t\t5.TO LIST ";
cout<<"\n\t\t\t6.TO QUIT\n";
cin>>ch;
}
while((ch!=1)&&(ch!=2)&&(ch!=3)&&(ch!=4)&&(ch!=5)&&(ch!=6)];
return(ch);
}
//----------------------------------------------------------------
//
void criminal::modify()
{
clrscr();fstream file;char
npdr[10],ncrime[10],nact[10],ncourt[10],nstat[10],nfir[10];
char str[10],nprd[15],cno[10];
int check,loc;
criminal x;
date D;
cout<<"\n MODIFICATION FUNCTION ";
cout<<"\n ENTER THE CONVICT NUMBER OF THE CONVICT,TO BE MODIFIED:";
gets(str);
check=this->dcheck(str);
if(check!=0)
{
file.open("jail.dat",ios::out(ios::ate);
int d=0;
while(!d)
{
cout<<"\n ENTER THE MODIFIED CONVICT NO :";
gets(cno);
d=x.concheck(cno);
}
strcpy(conno,cno);
cout<<"\n ENTER THE MODIFIED CRIME :";
gets(ncrime);
strcpy(COURT.crime,ncrime);
cout<<"\n ENTER THE MODIFIED COURT RECORD: ";
cout<<"\n ACT :";
gets(nact);
strcpy(COURT.act,nact);
cout<<"\nSTATE:";
gets(nact);
strcpy(COURT.state,nstate);
cout<<"\nCOURT:";
gets(ncourt);
strcpy(COURT.cour,ncourt);
clrscr();
cout<<"\n ENTER THE MODIFIED POLICE RECORD ";
cout<<"\n STATION:";
gets(nstat);
strcpy(POLICE.station,nstat);
cout<<"\nFIR NO :";
gets(nfir);
strcpy(POLICE.fir_no.nfir);
cout<<"\nDate OF ARREST(dd,mm.yyy)";
int c=0
while(!c)
{
cout<<"\n\t\t\t\t\t day:";
cin>>D.d;
if((D.d>31)||(D.d<1))
{
cout<<"\n\n THIS DATE DOES NOT EXIST,TRY AGAIN!! ";
c=0;
}
else
c=1
}
c=0;
while(!c)
{
cout<<"\n\t\t\t\t\t month:";
cin>>D.m;
if((D.m>12)||(D.m<1))
{
cout<<"\n\n THIS MONTH DOES NOT EXIST,TRY AGAIN!! ";
c=0;
continue;
}
else
c=1;
if((D.d==31)&&(D.m==2)||(D.m==4)||(D.m==6)||(D.m==9)||
(D.m==11)
{
cout<<"\n\n THIS MONTH DOES NOT HAVE #! DAYS,TRY AGAIN!! ";
c=0;
}
else
c=1;
}
c=0;
while(!c)
{
cout<<"\n\n\t\t\t\t year (in 4 digits):";
cin>>D.y;
if(D.y<=1930)||(D.y>2009))
{
cout<<"\n incorrect INput";
c=0;
}
else
c=1;
}
POLICE.date_arrest.d=D.d;
POLICE.date_arrest.m=D.m;
POLICE.date_arrest.y=D.y;
loc=(check=1)*sizeof(criminal);
file.seekp(loc);
file.write((char*)this,sizeof(criminal));
file.close();
}
}
//***********************************
//
void criminal::list()
{
clscr();
int j;
fstream file;
file.open("jail.dat",ios::in|ios::ate|ios::bianry);
int q=file.tellg();
int c=q/sizeof(criminal);
file.seekg(0);
cout<<" ";
cout<<" CONVICT LIST ";
cout<<" ";
cout<<"SNO/tNAME/t/tCONVICT NO./t/t/t ";
int i=0;
while(file.read((char*)this,sizeof(criminal)))
{
i++;
cout<<i<<"";
for(j=0;j<strlen(this->name);j++)
cout<<this->COURT.crime[j];
cout<<"/n---------------------------------------------------------/n";
if(i%3==0 &&(i!=c))
{
cout<<"pRESS A KEY TO CONTINUE";
getch();
clscr();
cout<<"/n---------------------------------------------------------/n";
cout<<"SNO/tNAME/t/tCONVICT NO./t/t/t ";
}}
file.close();
}
//-----------------------------------------------------------
//
void criminal::empty()
{
int i;
for(i=0;i<20;i++)
name[i]='';
for(i=0;i<10;i++)
conno[i]='';
for(i=0;i<3;i++)
age[i]='';
for(i=0;i<50;i++)
address[i]='';
for(i=0;i<20;i++)
COURT.cour[i]='';
for(i=0;i<20;i++)
COURT.crime[i]='';
for(i=0;i<20;i++)
COURT.act[i]='';
for(i=0;i<20;i++)
COURT.state[i]='';
for(i=0;i<20;i++)
des.colour[i]='';
for(i=0;i<20;i++)
des.imark[i]='';
for(i=0;i<20;i++)
des.face[i]='';
for(i=0;i<20;i++)
des.height[i]='';
for(i=0;i<50;i++)
POLICE.station[i]='';
for(i=0;i<50;i++)
POLICE.fir_no[i]='';
POLICE.date_arrest.m=0;
POLICE.date_arrest.d=0;
POLICE.date_arrest.y=0;
}
//_______________________________
//
int criminal::concheck(char b[])
{
fstream file;char a[10];
int check=0;
file.open("jail.dat",ios::in|ios::ate);
int q=file.tellg();
int size=q/sizeof(criminal);
file.seekg(0,ios::beg);
for(int i=0;i<size;i++);
{
file.read((char*)this,sizeof(criminal));
strcpy(a,conno);
if(strcmp(b,a)==0)
{check+=1;
break;
}}
if(check==0)
{return (10);
}
{cout<<"/nGIVEN CONVICT CODE ALREADY EXISTS:";
return(0);
}
file.close();
}
void main()
{
clrscr();int x;
for(int i=0;i<3;i++)
clrscr();
cout<<"CRIMINAL RECORD/n/n/t/t/t<BY AIMANRAZA";
cout<<"ENTER PASSWORD";
char*pass;
cin>>pass;
x=strcmp(pass,"aiman");
if (x==0)
{
cout<<"";
}
else
cout
<<"/a";
}}
if(x==0)
{
int choice,ans='y';
criminal l;
while((ans=='y'||ans=='Y'))
{
choice=l.menu();
switch(choice)
{
case 1:
l.input();
break;
case 1:
l.input();
break;
case 2:
l.modify();
break;
case 3:
l.display();
break;
case 4:
l.remove();
break;
case 5:
l.list();
break;
case 6:
exit(0);
}
cout<<"/n/n/nDO YOU WANT TO CONTINUE(press y to continue)";
ans=getch();
if((ans=='y'||ans=='Y')
continue;
}
}}
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Note: Backticks are not single quotes.
if you need help you also should say what your code should do, what’s not working, what have you tried so far…
with a block of code like that, if you don’t say what it should do, the most someone can do to help you, is find syntax errors
1 Like
More details please? It’s a bit, hard to help you now…
yes its a bit hard to understand