Police Station Management System using C++

Police Station Management System using C++ (With Source Code)

 Police Station Management System using C++ (With Source Code)

Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a Police Station Management System using C++ (With Source Code).

A Police Station Management System written in C++ programming language is a console based application which allows the user to perform various operations such as adding, modifying, displaying, deleting and listing criminal records. This project uses object-oriented programming for the concept of classes in C++. The program controls criminal activity recording and creates First Information Reports (F.I.Rs). Structures for recording date information, crime data, physical descriptions of offenders, and police records are included. The code also includes functions/methods for authenticating users and providing loading effects.

 Police Station Management System using C++

It contains a number of header files for input/output, text manipulation, file management, and so on. This system is easy to create and understand. It makes the whole process of adding, storing and manipulation of the records easy as a user can do this using this system in an efficient and a time-saving manner.

Palindrome Checker using Stack in C++ (With Source Code)

Objective of the System:

The goal of the Police Station Management System code is to provide a computerised solution for controlling criminal activity within a police station in an effective manner. It Streamlines the data recording by allowing  the systematic recording of crimes, including precise information such as date, time, location, and description, to guarantee accurate and thorough documentation. To automate the process of creating First Information Reports (F.I.Rs) for reported offences, decreasing manual paperwork and enhancing report creation speed and accuracy and improving criminal profile management. It will enhance Security and Access Control by implementing user authentication to guarantee that only authorized users may access the site.

Features of the System:

These characteristics are intended to increase the efficiency and efficacy of Police station management system:

  1. Authentication of user via login process. It guarantees secure system access by requiring users to authenticate themselves before utilizing the system’s functions.
  2. Criminal information recording, the system enables for the recording and storage of information concerning criminal acts, such as the date, time, location, and description of the offence.
  3. Performing of various operations on the criminal records such as – adding of records, modification of records, display if records, deletion of records, listing of records and exiting from the program.
  4. Generation of First Information Reports (F.I.Rs): The code allows for the creation of F.I.Rs, which are official papers that summarize the contents of a reported crime.
  5. Loading effects are included in the code to improve the user experience by giving visual feedback during time-consuming activities.

Overview of the UI:

  • The main menu of options for operations that can be performed in the system:
 ——————————————————–
 |POLICE STATION MANAGEMENT SYSTEM|
 ——————————————————–
1. ADD RECORD
2. MODIFY RECORD
3. DISPLAY RECORD
4. DELETE RECORD
5. LIST ALL RECORDS
6. EXIT
Choose Option:[1/2/3/4/5/6] :

The user will choose an option to perform the operation of their choice. User will then enter a values according to the prompts that will be displayed on the console to perform that operation.

 Police Station Management System Source code:

You can directly use this code by copying it in your IDE to understand the working and then can create it by understanding the project.

/* Police Station Management System using C++ and compiled using GCC Compiler */

#include<iostream>
#include<conio.h>
#include<ctype.h>
#include<direct.h>
#include<process.h>
#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<fstream>
#include<string.h>
#include<stdlib.h>
#include<iomanip>
#include<time.h>


using namespace std;

/* Defining functions */

int login();      // function for loginscreen
void mainpage();  // function to display mainpage
void date1();     // to get current date
void delay();     // function for loading effect
void callExit();  // exit function


/* Structure for Date of arrest */

struct date
{
  int d;
  int m;
  int y;
};

/* Structure for Details of Crime of Criminal */

struct court
{
  char crime[20];
  char act[20];
  char cour[20];
  char state[20];
};

/* Structure for Physical Description of Criminal */

struct descp
{
  char colour[20];
  char face[20];
  char imark[20];
  char height[6];
  char eye_color[20];
};

/* Structure  for Details of F.I.R. */

struct police
{
  char station[50];
  char fir_no[10];
  date date_arrest;
};

int login()
{
  char username[30];
  char password[30];
  int true1 = 1;
  int try1 = 0;
  int i=0;
  do
  {
    system("cls");
    cout << "\n\n\n\n\n\n";
    cout <<"\t\t\t\t    ----------------------------------\n";
    cout <<"\t\t\t\t    |POLICE STATION MANAGEMENT SYSTEM|\n";
    cout <<"\t\t\t\t    ----------------------------------\n";
    cout <<"\n\n";
    cout << "\t\t\t\t\t";
    cout << "Username : ";
    cin >> username;
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Password : ";
    cin >> password;
    if(strcmp(username,"admin")==0 && strcmp(password,"pass")==0)
      {
        cout << "\n\n";
        cout << "\t\t\t\t";
        cout << "You are accessed to the system!\n\n";
        cout << "\t\t\t\t";
        system("pause");
        system("cls");
        true1 = 0;
        return 1;
      }
      else
      {
        system("cls");
        try1 = try1+1;
        cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
        cout << "\t\t\t\t\t";
        cout << "No. of attempts remain: " << 3-try1;
        cout << "\n\n";
        cout << "\t\t\t\t";
        system("pause");
        if(try1>=3)
        {

          cout << "\t\t\t\t\t\t";
          cout << "\n";
          cout << "\t\t\t\t";
          cout << "No permission to enter the system!\n\n";
          cout << "\t\t\t\t";
          system("pause");
          callExit();
        }
      } //END OF ELSE
    }
 while(try1<3);
}

void delay(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}

void mainpage()
{
  int process=0;
  system("cls");
  date1();
  cout << "\n";
  cout <<"\t\t\t\t    ----------------------------------\n";
  cout <<"\t\t\t\t    |POLICE STATION MANAGEMENT SYSTEM|\n";
  cout <<"\t\t\t\t    ----------------------------------\n";
  cout <<"\n\n";
  cout <<"\t\t\t\t";
  cout <<"Prepared By    ";
  cout <<":";
  cout <<"   Chetan Khunti";
  cout <<"\n\n";
  cout <<"\t\t\t\t";
  cout <<"Mini Project   ";
  cout <<":";
  cout <<"   Police Station Management System";
  cout <<"\n\n";
  cout <<"\t\t\t\t";
  cout <<"\n\n";
  cout <<"\n\n";
  cout <<"\t\t\t\t";
  system("pause");
  cout <<"\n\t\t\t\tLoading";

  for(process=0;process<25;process++)
  {
    delay(150);
    cout <<".";
  }
}

void callExit()
{
  int process = 0;
  system("cls");
  cout << "\n\n\n\n\n";
  cout << "\n\tTaking You Out of The System";
  for(process=0;process<25;process++)
    {
      delay(150);
      cout <<".";
    }
  system("cls");
  cout <<"\n\n\n\n\n\n\n\n\n\n\n";
  cout <<"\t\t\t\t\t";
  cout <<"You are out of the System.\n";
  cout <<"\t\t\t\t\t\t";
  cout << "Thank You !";
  cout <<"\n\n";
  cout <<"\t\t\t\t\t";
  system("pause");
  exit(0);
}

void date1()
{
  time_t T= time(NULL);
  struct  tm tm = *localtime(&T);
  cout << "\n\n\n";
  cout << "\t\t\t\t\t   Date:" << tm.tm_mday << "/" << tm.tm_mon+1  << "/" << tm.tm_year+1900 << "\n";
}

/* "CRIMINAL" class for getting all information about convict */

class criminal
{
private:
  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[]);                 // function to check that input is non-numeric
  int s_check(char a[]);                  // function to check sex has only 1 character "M" or "F"
  void input(void);                       // function to take input
  void output(void);                      // function for displaying output
  void delete_rec(char con_no[]);         // function to delete a record
  int dcheck(char n[]);                   // function to search convict id in file
  void display();                         // function to display all records
  void remove();                          // function to remove an entry
  void modify();                          // function to modify existing records
  void list();                            // function to list all records
  void empty();                           // function to enter new record while modifying
  int concheck(char b[]);                 // function to check convict ID

};

// end of class criminal

void menu(criminal l)
{
  int input;
  while(true)
  {
    system("cls");
    cout << "\n\n\n";
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t    ----------------------------------\n";
    cout << "\t\t\t\t    |POLICE STATION MANAGEMENT SYSTEM|\n";
    cout << "\t\t\t\t    ----------------------------------\n";
    cout << "\n\n\n\n";
    cout << "\t\t\t\t";
    cout << " 1. ADD RECORD\n\n";
    cout << "\t\t\t\t";
    cout << " 2. MODIFY RECORD\n\n" ;
    cout << "\t\t\t\t" ;
    cout << " 3. DISPLAY RECORD\n\n" ;
    cout << "\t\t\t\t" ;
    cout << " 4. DELETE RECORD\n\n" ;
    cout << "\t\t\t\t" ;
    cout << " 5. LIST ALL RECORDS\n\n" ;
    cout << "\t\t\t\t" ;
    cout << " 6. EXIT\n\n" ;
    cout << "\t\t\t\t" ;
    cout << "Choose Option:[1/2/3/4/5/6] : " ;
    fflush(stdin);
    cin >> input;
    switch(input)
    {
      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:
      {
        callExit();
      }
      break;

      default:
      {
        cout << "\n\n\n" ;
        cout << "\t\t\t\t" ;
        cout << "      Invalid input!" ;
        cout << "\n\n" ;
        cout << "\t\t\t\t" ;
        fflush(stdin);
        getchar();
        menu(l);
      }
    }
  }
}

/* function to check that input is non-numeric */

int criminal::ncheck (char arr[])
{
  int i=0;
  while (arr[i]!='\0')
  {
    if (((arr[i] > 64) && (arr[i] < 92)) || ((arr[i] > 95) && (arr[i] < 124)) || (arr[i] ==' '))
    {

      i++;
      continue;
    }
    else
    {
      cout << "\n\tIncorrect input. Try again !\n ";
      return 0;
    }
  }
  return 1;
}

/* function to check sex has only 1 character "M" or "F" */

int criminal::s_check(char a[])
{
  if(( (a[0]=='m')||(a[0]=='f')||(a[0]=='M')||(a[0]=='F'))&&(a[1]=='\0') )
  {
    return 1;
  }
  else
  {
    cout << "\n\tIncorrect input. Try again !\n";
    return 0;
  }
}

void criminal::input()      // Function for getting Convicts Record


{
  system("cls");
  this->empty();
  criminal x;
  int c = 0 ;
  fflush(stdin);
  fstream filin;
  filin.open("jail.txt",ios::app);

  while(c != 1)
  {
    cout << "\n\n\n\tENTER THE CONVICT ID : ";
    cin >> (this->conno);
    c = x.concheck(this->conno);
    fflush(stdin);
  }
  c = 0;
  cout <<"\n\n    ENTER THE CONVICT DETAILS\n";
  while(c != 1)
  {
    cout  << "\n" << setw(10) <<"\tNAME    : ";
    cin >> (this->name);
    c = ncheck(this->name);
  }
  fflush(stdin);
  c = 0;
  while(c != 1)
  {
    cout << "\n" << setw(10) << "\tSEX     : ";
    cin >> (this->sex);
    c = s_check(this->sex);
  }
  fflush(stdin);
  cout << "\n" << setw(10) << "\tADDRESS : ";
  cin >> (this->address);
  fflush(stdin);
  cout << "\n" << setw(10) << "\tAGE     : ";
  cin >> (this->age);

  cout <<"\n\n   ENTER THE COURT DETAILS\n";
  fflush(stdin);
  c = 0 ;
  while(c != 1)
  {
    cout <<"\n\n\tCOURT OF CONVICTION : ";
    cin >> (this->COURT.cour);
    c = ncheck(this->COURT.cour);
  }
  fflush(stdin);
  c = 0;
  while(c != 1)
  {
    cout << "\n\tSTATE : ";
    cin >> (this->COURT.state);
    c = ncheck(this->COURT.state);
  }
  fflush(stdin);
  c = 0;
  while(c != 1)
  {
    cout << "\n\tCRIME : ";
    cin >> (this->COURT.crime);
    c = ncheck(this->COURT.crime);
  }
  fflush(stdin);
  cout << "\n\tACT   : ";
  cin >> (this->COURT.act);

  system("cls");

  cout << "\n    ENTER DESCRIPTION\n\n\t ";
  fflush(stdin);
  c = 0;
  while(c != 1)
  {
    cout<<"\n\tSKIN COMPLEXTION : ";
    cin >> (this->des.colour);
    c = ncheck(this->des.colour);
  }
  fflush(stdin);
  c = 0;
  while(c != 1)
  {
  cout << "\n\tFACE DESCRIPTION : ";
  cin >> (this->des.face);
  c = ncheck(this->des.face);
  }
  fflush(stdin);
  cout << "\n\tHEIGHT : ";
  cin >> (this->des.height);

  fflush(stdin);
  cout << "\n\tIDENTIFICATION MARKS : ";
  cin >> (this->des.imark);
  fflush(stdin);
  cout << "\n\tEYE COLOUR : ";
  cin >> (this->des.eye_color);

  system("cls");

  cout << "\n\n    ENTER POLICE STATION INFORMATION \n\n\t\t ";
  cout << "\n\n\n\t\t";
  fflush(stdin);
  cout << "\n\t\tPOLICE STATION : ";
  cin >> (this->POLICE.station);
  cout <<"\n\t\tFIR NO. : ";
  fflush(stdin);
  cin >> (this->POLICE.fir_no);
  cout <<"\n\t\tDATE OF ARREST(DD/MM/YYYY)\n";
  fflush(stdin);
  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\t\tTHIS DATE DOES NOT EXIST, TRY AGAIN!!\n";
      c = 0;
    }
    else
      c = 1;
  }
  c = 0;
  fflush(stdin);
  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\t\tTHIS MONTH DOES NOT EXIST, TRY AGAIN!!\n";
      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.m==11)))
    {
      cout <<"\n\t\tTHIS MONTH DOES NOT HAVE 31 DAYS \n\tTRY AGAIN !!\n";
      c = 0;
    }
    else
      c = 1;
  }
  fflush(stdin);
  c = 0;

  while(!c)
  {
    cout << "\n\t\t\t\t\t Year(4 digits) : ";
    cin >> this->POLICE.date_arrest.y;
    if((this->POLICE.date_arrest.y <= 1930)||(this->POLICE.date_arrest.y>2017))
    {
      cout << "\n\t\tINCORRECT INPUT, TRY AGAIN!!\n";
      c = 0;
    }
    else
      c = 1;
  }
  char ch;
  do
  {
    cout << "\n\tDO YOU WANT TO SAVE THIS INFORMATION(Y/N) : ";
    cin >> ch;

    if(ch=='y'||ch=='Y')
    {
      cout << "\n\n\t< RECORD HAS BEEN SAVED >";
      filin.write((char*)this,sizeof(criminal));
    }
   else
    {
      if((ch!='n')&&(ch!='N'))
      {
        cout<<"\n\t\tENTER CORRECTLY \n\t\t TRY AGAIN !!\n\n";
      }
    }
  }
  while((ch!='y') && (ch!='Y') && (ch!='n') && (ch!='N'));

  filin.close();
  cout << "\n\n\t\t";
  system("pause");

}

void criminal::output()      // Function for showing Convict's Record
{
  system("cls");
  fflush(stdin);

  cout << "\n\n\t\t----------PERSONAL RECORD OF CONVICT----------";
  cout << "\n\n\tCONVICT ID           :\t";
  puts(conno);
  cout << "\n\tNAME                 :\t";
  puts(this->name);
  cout << "\n\tSEX                  :\t" << this->sex;
  cout << "\n\n\tADDRESS              :\t";
  puts(this->address);
  cout << "\n\tAGE                  :\t";
  puts(this->age);
  cout << "\n\n\n\t\t\t";
  system("pause");


  system("cls");
  cout << "\n\n\t\t----------CRIMINAL RECORD----------";
  cout << "\n\n\t\t\tCOURT INFORMATION\n\n ";
  cout << "\n\t1. COURT OF CONVICTION        :\t";
  puts(this->COURT.cour);
  cout << "\n\t2. STATE                      :\t";
  puts(this->COURT.state);
  cout << "\n\t3. CRIME                      :\t";
  puts(this->COURT.crime);
  cout << "\n\t4. ACT                        :\t";
  puts(this->COURT.act);
  cout << "\n\n\n\t\t\t";
  system("pause");
  system("cls");

  cout << "\n\n\t\t\tDESCRIPTION\n";

  cout << "\n\t1. SKIN COMPLEXTION    :\t";
  puts(this->des.colour);
  cout << "\n\t2. FACE                :\t";
  puts(this->des.face);
  cout << "\n\t3. IDENTIFICATION MARK :\t";
  puts(this->des.imark);
  cout << "\n\t4. HEIGHT              :\t";
  puts(this->des.height);
  cout << "\n\t5. EYE COLOUR          :\t";
  puts(this->des.eye_color);
  cout << "\n\n\n\t\t\t";
  system("pause");

  system("cls");

  cout << "\n\n\n\t\tPOLICE INFORMATION \n\n";
  cout << "\n\t1. POLICE STATION    :\t";
  puts(this->POLICE.station);
  cout << "\n\t2. FIR NO.           :\t";
  puts(this->POLICE.fir_no);
  cout << "\n\t3. DATE OF ARREST    :\t" << this->POLICE.date_arrest.d <<"/" << POLICE.date_arrest.m << "/"<<this->POLICE.date_arrest.y;
  cout << "\n\n\n\t\t\t";
  system("pause");
}               //end of output function


void criminal::delete_rec(char con_no[]) // function for deleting a record
{
  fstream filin;
  fflush(stdin);
  filin.open("jail.txt",ios::in|ios::ate);
  int q = filin.tellg();
  int c = q/sizeof(criminal);
  fstream temp;
  temp.open("temp.txt",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.txt",ios::out);
  temp.open("temp.txt",ios::in|ios::ate);
  int a = temp.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\t\t< THE RECORD HAS BEEN DELETED >";
  cout <<"\n";
  fflush(stdin);
  getchar();
}

int criminal::dcheck(char n[]) // function to check correct format of date
{
  system("cls");
  fstream file;
  file.open("jail.txt",ios::in|ios::ate|ios::binary);

  int x = 0, count = 0, c;
  int q = file.tellg();
  c = q/sizeof(criminal);
  file.close();
  file.open("jail.txt",ios::in|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\n\n\n\tCONVICT NOT FOUND!! ";
    getchar();
    return 0;
  }
  else
  {
    return count;
  }
  file.close();
}

void criminal::display()    // function to display record
{
  system("cls");
  fflush(stdin);
  char N[10];
  int rec;
  int loc;
  cout << "\n\n\n\t\tENTER THE CONVICT ID : ";
  gets(N);
  fstream file;
  rec = this->dcheck(N);
  file.open("jail.txt",ios::in|ios::binary);
  if(rec!=0)
  {
    loc = (rec-1)*sizeof(criminal);
    file.seekg(loc);
    file.read((char*)this,sizeof(criminal));
    this->output();
  }
file.close();
cout <<"\n";
fflush(stdin);
}

void criminal::remove()
{
  fflush(stdin);
  system("cls");
  char no[10];
  int s;
  cout << "\n\n\n\t\tENTER THE CONVICT ID : ";
  gets(no);
  s = this->dcheck(no);
  if(s!=0)
  this->delete_rec(no);
}


void criminal::modify() // function to modify record
{
  system("cls");
  fflush(stdin);
  fstream file;
  char npdr[10], ncrime[10], nact[10], nstate[10], ncourt[10], nstat[10], nfir[10];
  char str[10],nprd[15],cno[10];
  int check,loc;
  criminal x;
  date D;
  fflush(stdin);
  modify_start:
  cout << "\n\tENTER CONVICT ID : ";
  gets(str);
  check = this->dcheck(str);
  if(check != 0)
  {
    file.open("jail.txt",ios::out|ios::ate);
    int d = 0;
    cout << "\n\n\t\tRECORD FOUND !\n\n";
    cout << "\n\tENTER MODIFIED DETAILS\n";
    while(d != 1)
    {
      cout << "\n\t\t\t\tCONVICT ID : ";
      cin >> cno;
      d = x.concheck(cno);
    }
    strcpy(conno,cno);

    cout << "\n\t\t\t\tCRIME      : ";
    cin >> ncrime;
    strcpy(COURT.crime,ncrime);
    cout << "\n\t\t\t\tACT   : ";
    cin >> nact;
    strcpy(COURT.act,nact);
    cout << "\n\t\t\t\tSTATE : ";
    cin >> nstate;
    strcpy(COURT.state,nstate);
    cout << "\n\t\t\t\tCOURT : ";
    cin >> ncourt;
    strcpy(COURT.cour,ncourt);
    system("cls");
    cout << "\n\t\tENTER THE  MODIFIED POLICE RECORD\n";
    cout << "\n\t\t\t\tSTATION : ";
    cin >> nstat;
    strcpy(POLICE.station,nstat);
    cout << "\n\t\t\t\tFIR NO   : ";
    cin >> nfir;
    strcpy(POLICE.fir_no,nfir);
    cout << "\n\t\t\t\tDATE OF ARREST(DD,MM,YYYY)  ";
    int c = 0;
    while(c != 1)
    {
      cout<<"\n\t\t\t\t\t Day : ";
      cin>>D.d;
      if((D.d>31)||(D.d<1))
      {
        cout << "\n\t\tTHIS DATE DOES NOT EXIST, TRY AGAIN!!\n";
        c = 0;
      }
      else
        c = 1;
    }

    c = 0;
    while(c != 1)
    {
      cout<<"\n\t\t\t\t\t Month : ";
      cin >> D.m;
      if((D.m>12)||(D.m<1))
      {
        cout << "\n\t\tTHIS MONTH DOES NOT EXIST, TRY AGAIN!!\n";
        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\t\tTHIS MONTH DOES NOT HAVE 31 DAYS \n\tTRY AGAIN !!\n";
        c = 0;
      }
      else
        c = 1;
    }
    c = 0;

    while(c != 1)
    {
      cout<<"\n\t\t\t\t\t Year(in 4 digits) : ";
      cin >> D.y;
      if((D.y <= 1930)||(D.y>2017) )
      {
        cout << "\n\t\tINCORRECT INPUT, TRY AGAIN!!\n";
        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();
    cout <<"\n";
    fflush(stdin);
    cout << "\n\n\t\t\t < RECORD MODIFIED >";
  }

  else
  {
      cout << "\n\n\n\t\tPRESS 'Y' TO TRY AGAIN 'N' TO GO TO QUIT : ";
      char ch_m;
      cin >> ch_m;
      fflush(stdin);
      if(ch_m == 'y' || ch_m == 'Y')
      {
        system("cls");
        goto modify_start;
      }

      else
      {
        callExit();
      }
  }
}

void criminal::list() // function to list all criminal records
{
  system("cls");
  fflush(stdin);
  int j ;
  fstream file;
  file.open("jail.txt",ios::in|ios::ate|ios::binary);
  int q = file.tellg();
  int c = q/sizeof(criminal);
  file.seekg(0);
  cout<<"                            \n";
  cout<<"		                                 \n";
  cout<<"                                CONVICT  LIST    \n";
  cout<<"			                         \n";
  cout<<"                            \n";
  cout<<"\n================================================================================\n";
  cout<<"SR.\tNAME\t\t\tCONVICT NO.\t\t\tCRIME\n";
  cout<<"================================================================================\n";
  int i = 0;
  while(file.read((char*)this,sizeof(criminal)))
  {
    i++;
    cout << i << "       ";
    for(j=0; j<strlen(this->name); j++)
      cout << this->name[j];
    cout<<"\t\t\t    ";
    for(j=0; j<strlen(this->conno); j++)
      cout << this->conno[j];
    cout << "\t\t\t        ";
    for(j=0; j<strlen(this->COURT.crime); j++)
      cout << this->COURT.crime[j];
      cout <<"\n";
      fflush(stdin);
      getchar();
    cout << "\n--------------------------------------------------------------------------------\n";
    if((i%3)==0&&(i!=c))
    {
      system("pause");
      system("cls");
      cout << "\n================================================================================\n";
      cout << "SR.\tNAME\t\t\tCONVICT NO.\t\t\tCRIME\n";
      cout << "================================================================================\n";
    }
  }
  file.close();
  getchar();
}

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++)
    sex[i]=' ';
  for(i=0; i<4; 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<6; i++)
    des.height[i]=' ';
  for(i=0; i<15; i++)
    des.eye_color[i]=' ';
  for(i=0; i<50; i++)
    POLICE.station[i]=' ';
  for(i=0; i<10; 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 1;
  }
  else
  {
    cout<<"\tGIVEN CONVICT CODE ALREADY EXISTS!"<<endl;
    return 1;
  }
  file.close();
}

int main()
{
  system("cls");
  mainpage();
  criminal l;
  int x,res=1;
  res = login();

  if(res == 1)
  {
    menu(l);
  }
}

Now let us understand the code:-

  • We will start by writing the header of the code with the required libraries – iostream  (input and output stream), conio.h (console input/output), ctype.h, direct.h, process.h, windows.h, string.h, stdio.h, fstream, string.h (string manipulation), stdlib.h (memory management), iomanip ( Input/output Manipulator), time.h (time management).
  • Now we will give forward declarations for the functions – login() function for login screen, mainpage() function to display main page, date1() to get current date, delay() function for loading effect, callExit() function for exit.
  • We will create structures to store information. Creating a structure called ‘date’ for storing date of arrest, with 3 variables – d for date, m for month and y for year.
  • Create a structure called ‘court’ to store details of Crime of Criminal. This structure will contain 4 char type arrays – crime[20]; char act[20]; char cour[20]; char state[20].
  • Create a structure called ‘descp’, it will store physical Description of Criminal. It will contain 5 char type arrays – colour[20]; face[20]; imark[20]; height[6]; eye_color[20].
  • Create a structure called ‘police’ to store details of F.I.R. It will contain 2char type arrays – station[50]; fir_no[10]; and a date type variable called date_arrest.
  • Now we will define the functions –
  • The login() function handles the login screen for system access. It will ask the user for a username and password from the user and if the entered details are correct then it permits access. For this system the username is admin and password is pass. We will write an if else statement for the access functionality. If the user reaches the maximum number of attempts for the login after entering wrong inputs, the system shows – “No permission to enter the system!” . the maximum number of attempts for this system are 3 but you change it according to you in the source code. It also displays a heading for the POLICE STATION MANAGEMENT SYSTEM.
  • The delay() function takes mseconds as an argument. It creates a delay on the console after the access has been granted to the user. It provides a loading effect.
  • The mainpage() function will display the main page of the program. It will display some information about the project and the current date. We will use a for loop for the process delay.
  • The callExit() function will initialize an integer type variable called process to 0 value. It will then clear the screen using system(“cls”); . This function will take the user out of the system and display this statement – “Taking You Out of The System”. Then we will create a delay for the execution using delay() function in a for loop.
  • The date1() function will get the current date and time and display it on the screen.
  • Now we will create a class called ‘criminal‘ which will contain the criminal data. It will have private data members – name[20], sex[3], conno[10], age[4], address[50]; court COURT, police POLICE, descp des.
  • We will declare the public member functions, the definitions for the functions will be outside the class using the scope resolution operator –
    ncheck(char arr[]) function to check that input is non-numeric,
    int s_check(char a[]) function to check sex has only 1 character “M” or “F”
    void input(void)  function to take input
    void output(void) function for displaying output, for showing Convict’s Record.
    void delete_rec(char con_no[])  function to delete a record
    int dcheck(char n[])  function to check correct format of date
    void display()  function to display all records
    void remove() function to remove an entry
    void modify() function to modify existing records
    void list() function to list all criminal records
    void empty() function to enter new record while modifying
    int concheck(char b[]) function to check convict ID
  • The menu() function is used to interact with the “criminal” class. It will display a menu with choices for adding, modifying, displaying, deleting, or listing records, as well as exiting the program. We will use a switch case to select between the options. The corresponding function will be called by the system upon selecting the option to perform that operation.

Patient Management System using C++ (With Source Code)

Final Output:-

Here is an example to show how this project works.

 Police Station Management System using C++

 Police Station Management System using C++

 Police Station Management System using C++

 Police Station Management System using C++

 Police Station Management System using C++

 Police Station Management System using C++

 Police Station Management System using C++

 Police Station Management System using C++

Conclusion

We have reached the end of this article and have a lot more projects in C++ coming so stay tuned. We have started with awesome and fun projects for you all to understand C++. Learning C++ by creating fun projects makes learning easy and interesting.

Restaurant Menu System using C++ (With Source Code)

If you enjoyed the article and learned something new today, let us know in the comments.

Thank you.

ADVERTISEMENT

Happy Reading! 🙂

ADVERTISEMENT

Follow: CodewithRandom

ADVERTISEMENT



Leave a Reply