Anda di halaman 1dari 13

//***************************************************************

//

HEADER FILE USED IN PROJECT

//****************************************************************

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>

//***************************************************************
//

CLASS USED IN PROJECT

//****************************************************************

class crime
{
char cno[6];
char cname[50];
char ctype[20];
char cgender[10];
char ccontactno[11];
char caddress[80];
char carea[60];

public:
void create_crime()
{
cout<<"\nNEW CRIMINAL ENTRY...\n\n";
cout<<"\nEnter The crime no. :";
cin>>cno;
cout<<"\n\nEnter The Name of The criminal : ";
gets(cname);
cout<<"\n\nEnter The Criminal Address :";
gets(caddress);
cout<<"\nEnter The criminal Gender : ";
cin>>cgender;
cout<<"\n\nEnter The criminal Mobile No : ";
gets(ccontactno);
cout<<"\n\nEnter The Crime Area : ";
gets(carea);
cout<<"\n\nEnter The Crime TYpe : ";
gets(ctype);

cout<<"\n\n\nCrime Created..";
}

void show_crime()
{
cout<<"\n\tCriminal No.\t\t: "<<cno;
cout<<"\n\n\tCriminal Name\t\t: ";

puts(cname);
cout<<"\n\tCriminal Address\t: ";
puts(caddress);
cout<<"\n\tCriminal Gender\t\t: ";
cout<<cgender;
cout<<"\n\n\tMobile No\t\t: ";
puts(ccontactno);
cout<<"\n\tCrime Area\t\t: ";
puts(carea);
cout<<"\n\tCrime Type\t\t: ";
puts(ctype);

void modify_crime()
{
cout<<"\nCime no.\t: "<<cno;
cout<<"\nModify The Name of The criminal : ";
gets(cname);
cout<<"\n\nModify The Criminal Address : ";
gets(caddress);
cout<<"\nModify The criminal Gender : ";
cin>>cgender;
cout<<"\nNodify The criminal Mobile No : ";
gets(ccontactno);
cout<<"\n\nModify The Crime Area : ";

gets(carea);
cout<<"\n\nModify The Crime Type : ";
gets(ctype);

char* retcno()
{
return cno;
}

void report()
{
cout<<setw(10)<<cno<<setw(12)<<cname<<setw(12)<<caddress<<setw(8)<<
cgender<<setw(12)<<ccontactno<<setw(12)<<carea<<setw(12)<<ctype<<endl
;
}

};

//class ends here

//***************************************************************
//

global declaration for stream object, object

//****************************************************************

fstream fp,fp1;
crime bk;

//***************************************************************
//

function to write in file

//****************************************************************

void write_crime()
{
char ch;
fp.open("crime.dat",ios::out|ios::app);
do
{
clrscr();
bk.create_crime();
fp.write((char*)&bk,sizeof(crime));
cout<<"\n\n\tDo you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}

//***************************************************************
//

function to read specific record from file

//****************************************************************

void display_spb(char n[])


{
cout<<"\n\t\tCRIME DETAILS\n";
int flag=0;
fp.open("crime.dat",ios::in);
while(fp.read((char*)&bk,sizeof(crime)))
{
if(strcmpi(bk.retcno(),n)==0)
{
bk.show_crime();
flag=1;
}
}

fp.close();
if(flag==0)
cout<<"\n\n\tCriminal does not exist";
getch();
}

//***************************************************************
//

function to modify record of file

//****************************************************************

void modify_crime()
{
char n[6];
int found=0;
clrscr();
cout<<"\n\n\tMODIFY CRIME REOCORD.... ";
cout<<"\n\n\tEnter The crime no. of The crime";
cin>>n;
fp.open("crime.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(crime)) && found==0)
{
if(strcmpi(bk.retcno(),n)==0)
{
bk.show_crime();
cout<<"\nEnter The New Details of crime"<<endl;
bk.modify_crime();
int pos=-1*sizeof(bk);

fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(crime));
cout<<"\n\n\t Record Updated";
found=1;
}
}

fp.close();
if(found==0)
cout<<"\n\n\t Criminal Not Found ";
getch();
}

//***************************************************************
//

function to delete record of file

//****************************************************************

void delete_crime()
{
char n[6];
clrscr();

cout<<"\n\n\n\tDELETE BOOK ...";


cout<<"\n\nEnter The Crime no. of To Delete : ";
cin>>n;
fp.open("crime.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(crime)))
{
if(strcmpi(bk.retcno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(crime));
}
}

fp2.close();
fp.close();
remove("crime.dat");
rename("Temp.dat","crime.dat");
cout<<"\n\n\tRecord Deleted ..";
getch();
}

//***************************************************************

//

function to display crime list

//****************************************************************

void display_allb()
{
clrscr();
fp.open("crime.dat",ios::in);
if(!fp)
{
cout<<"\tERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}

cout<<"\n\n\t\t\t\tCRIMINAL LIST\n\n";
cout<<"=============================================
=================================\n";
cout<<setw(10)<<"C_Code"<<setw(12)<<"C_Name"<<setw(12)<<"Address"<<s
etw(8)<<"Gender"<<setw(12)<<"Mobile_No"<<setw(12)<<"C_Area"<<setw(12)<
<"C_Type"<<"\n";
cout<<"=============================================
=================================\n";

while(fp.read((char*)&bk,sizeof(crime)))
{
bk.report();

}
fp.close();
getch();
}

//***************************************************************
//

INTRODUCTION FUNCTION

//****************************************************************

void intro()
{
clrscr();
gotoxy(35,11);
cout<<"CRIME REPORT";
gotoxy(35,14);
cout<<"MANAGEMENT SYSTEM";
gotoxy(35,17);

cout<<"\n\n\tMADE BY \t: SACHIN ";


cout<<"\n\n\tSCHOOL \t\t: Gagan Bharti Public School";
getch();
}

//***************************************************************
//

THE MAIN FUNCTION OF PROGRAM

//****************************************************************

void main()
{
char ch;
intro();
do
{
clrscr();
int ch2;
cout<<"\n\n\n\tADMINISTRATOR MENU";
cout<<"\n\n\t1.CREATE CRIME ";
cout<<"\n\n\t2.DISPLAY ALL CRIME ";
cout<<"\n\n\t3.DISPLAY SPECIFIC CRIME ";
cout<<"\n\n\t4.MODIFY CRIME ";
cout<<"\n\n\t5.DELETE CRIME ";
cout<<"\n\n\t6.BACK TO MAIN MENU";
cout<<"\n\n\tPlease Enter Your Choice (1-6) : ";
cin>>ch2;
switch(ch2)
{
case 1: clrscr();

write_crime();break;
case 2: display_allb();break;
case 3: {
char num[6];
clrscr();
cout<<"\n\n\tPlease Enter The crime No. ";
cin>>num;
display_spb(num);
break;
}
case 4: modify_crime();break;
case 5: delete_crime();break;
case 6: return;
default:cout<<"\a";

cout<<"\n\n\tpress y to continue :";


ch= getche();

}while(ch=='y');
}

//***************************************************************
//

END OF PROJECT

//***************************************************************

Anda mungkin juga menyukai