Prison Management System using C++

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

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

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

The Prison Management System is a console based software created using C++ Programming language. It is built on the idea of entering and managing the convicts’ records. The user may readily enter each prisoner’s information into this system. This system includes a login system. To erase a prisoner’s record, the user must also go through password verification. As a result, there is no risk of data loss or abuse, and it is not time-consuming.

Prison Management System using C++

This  project consists of several variables and strings have been employed in its construction. Users will find it simple to use and comprehend and create on their own.

Payroll Management System Using C++ (With Source Code)

Objective of the System:

A prison management system’s objective is to handle all areas of a prison facilities in an efficient and effective manner. Prisoner records, security, facility operations and prisoner management are all part of this. The system’s goals include improving security, streamlining administrative operations, ensuring accurate record-keeping, facilitating communication, and promoting rehabilitation and reintegration initiatives. Ultimately, the purpose is to keep offenders safe and secure while facilitating effective reintegration into society.

Features of the System:

  • Program consists of a login system and user can login using username and password.
  • It displays date and time.
  • We can add, store and display prisoner details.
  • The prisoner details can be deleted.
  • File can be converted into 3 different types – Text, HTML, Word file.
  • Prisoner can be searched and released.
  • User can logout of the system and exit.

Overview of the UI:

—————————————-
PRISON STATION MANAGEMENT SYSTEM
—————————————-
Username:
Password:

After entering the correct username and password, access will be granted and this will be displayed – You are accessed to the system!

Main Menu will be displayed after the access is given:
  1. New prisoner entry
  2.  Prisoner detail
  3. Attendance prisoner
  4. Release prisoner
  5. Search prisoner
  6. Prison File
  7. Logout
  8. Exit

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.

 

Prison Management System using C++ 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.

// username = admin
// password = pass

#include <iostream>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <fstream>
#include <ctime>
using namespace std;

void FrontPage(); // Front Page Or Main Page
void Date();      // Getting Date
void Time();      // Display time

class Prison
{
private:
    // Detaiils of Prisoner
    string First_Name[20] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "};
    string Second_Name[20];
    string Gender[20];
    int CellNo[20] = {1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020};
    int Age[20];
    double Height[20];
    string Eyecolor[20];
    string Crime[20];
    int Punishmentmonths[20];
    int o = 0;

public:
    void SetData();      // Set data of the prisoners
    void Details();      // Getting details of the prisoners
    void Afterlogin();   // After login page OR Menu function
    void Attendance();   // Storing attendace of the prisoners
    void Release();      // Release the prisoners
    void SearchPrison(); // Search Prison
    void PrisonFile();   // Priosn File
    void Logout();       // Logout
    void Exit();         // Exit function
    void Login();        //login
};

void Prison::Logout()
{
    system("cls");
    cout << "\n\n\n\n\n\n\t\t\t\t\t";
    cout << "logging out ";

    for (int x = 0; x < 15; x++)
    {
        for (int a = 0; a <= 100000000; a++)
        {
        }
        cout << ".";
    }
    Prison::Login();
}

void Prison::Login()
{

    char Username[15];
    char Password[15];
    char Epwd;
    int true1 = 1;
    int try1 = 0;
    int i = 0;

    do
    {
        system("cls");
        Time();
        cout << "\n\n\n\n\n\n";
        int a;
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t    ----------------------------------------\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t    |   PRISON STATION MANAGEMENT SYSTEM   |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t    ----------------------------------------\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        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 : ";
        for (i = 0;;)
        {
            Epwd = getch();
            if ((Epwd >= 'a' && Epwd <= 'z') || (Epwd >= 'A' && Epwd <= 'Z') || (Epwd >= '0' && Epwd <= '9'))
            {
                Password[i] = Epwd;
                ++i;
                cout << "*";
            }
            if (Epwd == '\b' && i >= 1)
            {
                cout << "\b \b";
                --i;
            }
            if (Epwd == '\r')
            {
                Password[i] = '\0';
                break;
            }
        }

        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;
            try1 = 4;
            Prison::Afterlogin();
        }
        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");
                exit;
            }
        }
    } while (try1 < 3);
}

void Prison ::SetData()
{
    system("cls");
    Time();
    int a, s;
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    -----------------------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    |                                                   |\n";
    cout << "\t\t\t\t    |         Enter basic information of prisoner       |\n";
    cout << "\t\t\t\t    |                                                   |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    -----------------------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\n\n";
    cout << "\t\t\t\t\t";
    cout << "Enter first name : ";
    cin >> First_Name[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter second name : ";
    cin >> Second_Name[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter gender : ";
    cin >> Gender[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter age : ";
    cin >> Age[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter height : ";
    cin >> Height[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter eyecolor : ";
    cin >> Eyecolor[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter crime : ";
    cin >> Crime[o];
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Enter punishment span in months : ";
    cin >> Punishmentmonths[o];
    cout << "\t\t\t\t\t";
    cout << "\n\n\n";
    cout << "\t\t\t\t\t";
    cout << "Your Cell No is " << CellNo[o];
    cout << "\n\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    o = o + 1;
    cout << "Press 1 to return : ";
    scanf("%d", &s);
    if (s == 1)
    {
        Prison ::Afterlogin();
    }
}

void Prison ::Details()
{
    system("cls");
    Time();
    int t;
    for (t = 0; t <= 100000000; t++)
    {
    }
    cout << "\t\t\t\t    -----------------------------------------------------\n";
    for (t = 0; t <= 100000000; t++)
    {
    }
    cout << "\t\t\t\t    |                                                   |\n";
    cout << "\t\t\t\t    |                Prisoner list                      |\n";
    cout << "\t\t\t\t    |                                                   |\n";
    for (t = 0; t <= 100000000; t++)
    {
    }
    cout << "\t\t\t\t    -----------------------------------------------------\n";
    for (t = 0; t <= 100000000; t++)
    {
    }
    int s, c = 0, p = 0;

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

    cout << "\n===========================================================================================================\n";
    cout << "SR.\tNAME\t\t\tCell Block\tAge\tGender\tHeight\tEye Colour\tCrime\tPunishment\n";
    cout << "===========================================================================================================\n";

    for (int x = 0; x <= 19; x++)
    {
        if (First_Name[x] != " ")
        {
            p++;
            cout << p << "\t" << First_Name[x] << "" << Second_Name[x] << "\t\t" << CellNo[x] << "\t\t" << Age[x] << "\t" << Gender[x] << "\t" << Height[x] << "\t" << Eyecolor[x] << "\t\t" << Crime[x] << "\t\t" << Punishmentmonths[x] << endl;
            cout << "\n"
                 << endl;
            c++;
        }
    }
    if (c == 0)
    {
        cout << "\n\t\t\t\t\t";
        cout << "No prisoner Present";
        cout << "\n";
        cout << "\t\t\t\t\t";
    }
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Press 1 to return : ";
    scanf("%d", &s);
    if (s == 1)
    {
        Prison::Afterlogin();
    }
}

void Prison ::Attendance()
{
    int s, l, c = 0;
    char ch;
    do
    {
        system("cls");
        Time();
        system("cls");
        int t;
        for (t = 0; t <= 100000000; t++)
        {
        }
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        for (t = 0; t <= 100000000; t++)
        {
        }
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    |           Prisoner attendance maintainer          |\n";
        cout << "\t\t\t\t    |                                                   |\n";
        for (t = 0; t <= 100000000; t++)
        {
        }
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        for (t = 0; t <= 100000000; t++)
        {
        }

        cout << "\n\t\t\t\t\t";
        cout << "\n===========================================================================================================\n";
        cout << "NAME\t\t\tCell Block\tAge\tGender\tHeight\tEye Colour\tCrime\tPunishment\n";
        cout << "===========================================================================================================\n";
        for (int x = 0; x <= 19; x++)
        {
            if (First_Name[x] != " ")
            {
                cout << First_Name[x] << "" << Second_Name[x] << "\t\t" << CellNo[x] << "\t\t" << Age[x] << "\t" << Gender[x] << "\t" << Height[x] << "\t" << Eyecolor[x] << "\t\t" << Crime[x] << "\t\t" << Punishmentmonths[x] << endl;
                cout << "\n"
                     << endl;
                c++;
            }
        }
        if (c != 0)
        {
            cout << "\n\t\t\t\t\t";
            cout << "Enter the cell  block of the prisoner :";
            scanf("%d", &l);
            l = l - 1001;
            cout << "\n\t\t\t\t\t";
            cout << "Name : ";
            cout << First_Name[l] << " " << Second_Name[l];
            Punishmentmonths[l]--;
            cout << "\n\t\t\t\t\t";
            cout << "Punishment for :" << Punishmentmonths[l] << " months";
            if (Punishmentmonths[l] <= 0)
            {
                cout << "\n\t\t\t\t\t";
                cout << "Prisoner is ready for release";
            }
            cout << "\n\n";
            cout << "\n\t\t\t\t\t";
            cout << "Press y to choose another prisoner and press n to exit :";
            cin >> ch;
        }
        else
        {
            int a;
            cout << "\t\t\t\t\t";
            cout << "\n";
            cout << "\t\t\t\t\t";
            for (a = 0; a <= 100000000; a++)
            {
            }
            cout << "\t\t\t\t                                                    \n";
            cout << "\t\t\t\t    ------------------------------------------------\n";
            for (a = 0; a <= 100000000; a++)
            {
            }
            cout << "\t\t\t\t    |             No prisoners present             |\n";
            for (a = 0; a <= 100000000; a++)
            {
            }
            cout << "\t\t\t\t    ------------------------------------------------\n";
        }

    } while (ch == 'y');
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Press 1 to return : ";
    scanf("%d", &s);
    if (s == 1)
    {
        Prison::Afterlogin();
    }
}

void Prison ::Release()
{
    int s, l, c = 0, r;
    char ch;
    do
    {
        system("cls");
        Time();
        int t;
        for (t = 0; t <= 100000000; t++)
        {
        }
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        for (t = 0; t <= 100000000; t++)
        {
        }
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    |                Release prisoner                   |\n";
        cout << "\t\t\t\t    |                                                   |\n";
        for (t = 0; t <= 100000000; t++)
        {
        }
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        for (t = 0; t <= 100000000; t++)
        {
        }

        cout << "\n\t\t\t\t\t";
        cout << "\n===========================================================================================================\n";
        cout << "NAME\t\t\tCell Block\tAge\tGender\tHeight\tEye Colour\tCrime\tPunishment\n";
        cout << "===========================================================================================================\n";

        for (int x = 0; x <= 19; x++)
        {
            if (First_Name[x] != " ")
            {
                cout << First_Name[x] << "" << Second_Name[x] << "\t\t" << CellNo[x] << "\t\t" << Age[x] << "\t" << Gender[x] << "\t" << Height[x] << "\t" << Eyecolor[x] << "\t\t" << Crime[x] << "\t\t" << Punishmentmonths[x] << endl;
                cout << "\n"
                     << endl;
                c++;
            }
        }
        if (c != 0)
        {
            cout << "\n\t\t\t\t\t";
            cout << "Enter the cell block of the prisoner :";
            scanf("%d", &l);
            l = l - 1001;
            cout << "\n\t\t\t\t\t";
            cout << "Name : ";
            cout << First_Name[l] << " " << Second_Name[l];
            cout << "\n\t\t\t\t\t";
            if (Punishmentmonths[l] <= 0)
            {
                cout << "\n\t\t\t\t\t";
                cout << "Prisoner is ready for release";
                cout << "\n\t\t\t\t\t";
                cout << "Press 1 to release the prisoner :";
                cin >> r;
                if (r == 1)
                {
                    First_Name[l] = " ";
                    Second_Name[l] = " ";
                    Gender[l] = " ";
                    Age[l] = 0;
                    Height[l] = 0;
                    Eyecolor[l] = " ";
                    Punishmentmonths[l] = 0;
                    cout << "\n\t\t\t\t\tProcessing";

                    for (int process = 0; process < 7; process++)
                    {
                        for (int a = 0; a <= 100000000; a++)
                        {
                        }
                        cout << ".";
                    }
                    cout << "\n\t\t\t\t\t";
                    cout << "Prisoner released successfully";
                }
            }
            else
            {
                cout << "\n\t\t\t\t\t";
                cout << "Prisoner is not ready for release";
            }

            cout << "\n\n";
            cout << "\n\t\t\t\t\t";
            cout << "Press y to choose another prisoner and press n to exit :";
            cin >> ch;
        }
        else
        {
            int a;
            cout << "\t\t\t\t\t";
            cout << "\n";
            cout << "\t\t\t\t\t";
            for (a = 0; a <= 100000000; a++)
            {
            }
            cout << "\t\t\t\t                                                    \n";
            cout << "\t\t\t\t    ------------------------------------------------\n";
            for (a = 0; a <= 100000000; a++)
            {
            }
            cout << "\t\t\t\t    |             No prisoners present             |\n";
            for (a = 0; a <= 100000000; a++)
            {
            }
            cout << "\t\t\t\t    ------------------------------------------------\n";
            break;
        }
    } while (ch == 'y');
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Press 1 to return : ";
    scanf("%d", &s);
    if (s == 1)
    {
        Prison::Afterlogin();
    }
}

void Prison ::SearchPrison()
{
    int info;
    int CN, i, a, s, l;
    int c = 0, p = 0;

    system("cls");
    cout << "\t\t\t\t    ----------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    |             Search Menu              |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    ----------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\n\n";
    cout << "\t\t\t\t";
    cout << "Enter the prisoner cell id to be searched : ";
    cin >> CN;
    cout << "\n\t\t\t\t";
    cout << "\n===========================================================================================================\n";
    cout << "NAME\t\t\tCell Block\tAge\tGender\tHeight\tEye Colour\tCrime\tPunishment\n";
    cout << "===========================================================================================================\n";
    l = CN - 1001;
    info = CellNo[l];
    if (CN == info)
    {
        if (First_Name[l] != " ")
        {
            cout << First_Name[l] << "" << Second_Name[l] << "\t\t" << CellNo[l] << "\t\t" << Age[l] << "\t" << Gender[l] << "\t" << Height[l] << "\t" << Eyecolor[l] << "\t\t" << Crime[l] << "\t\t" << Punishmentmonths[l] << endl;
            cout << "\n"
                 << endl;
        }
        else
        {
            cout << "\n";
            cout << "\t\t\t\t";
            cout << "\n";
            cout << "\t\t\t\t";
            cout << "cell block empty" << endl;
        }
    }
    else
    {
        cout << "\n";
        cout << "\t\t\t\t";
        cout << "\n";
        cout << "\t\t\t\t";
        cout << "invalid cell id" << endl;
    }
    cout << "\n";
    cout << "\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t";
    cout << "Press 1 to return : ";
    scanf("%d", &s);
    if (s == 1)
    {
        Prison::Afterlogin();
    }
}

void Prison ::PrisonFile()
{
    Time();
    system("cls");

    int format, a;
    int s, c = 0, p = 0;
    cout << "\n\n\n";
    cout << "\t\t\t\t-----------------------------------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t|                                                               |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t|                     1)   Txt File                             |\n";
    cout << "\t\t\t\t|                                                               |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t|                     2)   Html File                            |\n";
    cout << "\t\t\t\t|                                                               |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t|                     3)   Word File                            |\n";
    cout << "\t\t\t\t|                                                               |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t-----------------------------------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\n";
    cout << "\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t";
    cout << "In which format you want to open your file? ";
    cin >> format;
    std::ofstream MyFile_;
    switch (format)
    {
    case 1:
        Time();
        system("cls");
        cout << "\t\t\t\t\t";
        cout << "\n";
        cout << "\t\t\t\t\t";
        cout << "\n\n\n\n\n";
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    |        Txt File created successfully              |\n";
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    -----------------------------------------------------\n";

        MyFile_.open("Prison_Data.txt");

        MyFile_ << "\t\t\t\t    -----------------------------------------------------\n";
        MyFile_ << "\t\t\t\t    |                                                                            |\n";
        MyFile_ << "\t\t\t\t    |                Prisoner list                                     |\n";
        MyFile_ << "\t\t\t\t    |                                                                            |\n";
        MyFile_ << "\t\t\t\t    -----------------------------------------------------\n";

        MyFile_ << "\n\t\t\t\t\t";

        MyFile_ << "\n=====================================================================================================================\n";
        MyFile_ << "SR.\tNAME\t\t\tCell Block\tAge\t\tGender\tHeight\tEye Colour\tCrime\tPunishment\n";
        MyFile_ << "=======================================================================================================================\n";

        for (int x = 0; x <= 19; x++)
        {
            if (First_Name[x] != " ")
            {
                p++;
                MyFile_ << p << "\t" << First_Name[x] << "" << Second_Name[x] << "\t\t" << CellNo[x] << "\t" << Age[x] << "\t\t" << Gender[x] << "\t" << Height[x] << "\t\t" << Eyecolor[x] << "\t\t" << Crime[x] << "\t\t" << Punishmentmonths[x] << endl;
                MyFile_ << "\n"
                        << endl;
                c++;
            }
        }
        if (c == 0)
        {
            MyFile_ << "\n\t\t\t\t\t";
            MyFile_ << "No prisoner Present";
            MyFile_ << "\n";
            MyFile_ << "\t\t\t\t\t";
        }
        MyFile_.close();
        break;

    case 2:
        Time();
        system("cls");
        cout << "\t\t\t\t\t";
        cout << "\n";
        cout << "\t\t\t\t\t";
        cout << "\n\n\n\n\n";
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    |          Html File created successfully           |\n";
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    -----------------------------------------------------\n";

        MyFile_.open("Prison_Data.html");

        MyFile_ << "\t\t\t\t    -----------------------------------------------------";
        MyFile_ << "\t\t\t\t    |                                                   |";
        MyFile_ << "\t\t\t\t    |                Prisoner list                      |";
        MyFile_ << "\t\t\t\t    |                                                   |";
        MyFile_ << "\t\t\t\t    -----------------------------------------------------";
        MyFile_ << "<br>";

        for (int x = 0; x <= 19; x++)
        {
            if (First_Name[x] != " ")
            {
                MyFile_ << "First name: " << First_Name[x];
                MyFile_ << "<br>";
                MyFile_ << "Second name: " << Second_Name[x];
                MyFile_ << "<br>";
                MyFile_ << "Cell number: " << CellNo[x];
                MyFile_ << "<br>";
                MyFile_ << "Age: " << Age[x];
                MyFile_ << "<br>";
                MyFile_ << "Gender: " << Gender[x];
                MyFile_ << "<br>";
                MyFile_ << "Height: " << Height[x];
                MyFile_ << "<br>";
                MyFile_ << "Eye colour: " << Eyecolor[x];
                MyFile_ << "<br>";
                MyFile_ << "Crime: " << Crime[x];
                MyFile_ << "<br>";
                MyFile_ << "Punishment Months: " << Punishmentmonths[x];
                MyFile_ << "<br>";
                MyFile_ << "<br>";
                c++;
            }
        }
        if (c == 0)
        {

            MyFile_ << "<br>\t\t\t\t\t";
            MyFile_ << "No prisoner Present";
            MyFile_ << "<br>";
            MyFile_ << "\t\t\t\t\t";
        }
        MyFile_.close();
        break;

    case 3:
        Time();
        system("cls");
        cout << "\t\t\t\t\t";
        cout << "\n";
        cout << "\t\t\t\t\t";
        cout << "\n\n\n\n\n";
        cout << "\t\t\t\t    -----------------------------------------------------\n";
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    |          Word File created successfully           |\n";
        cout << "\t\t\t\t    |                                                   |\n";
        cout << "\t\t\t\t    -----------------------------------------------------\n";

        MyFile_.open("Prison_Data.doc");

        MyFile_ << "\t\t\t *** Prisoner list *** ";
        MyFile_ << "\n";

        for (int x = 0; x <= 19; x++)
        {
            if (First_Name[x] != " ")
            {
                MyFile_ << "First name: " << First_Name[x];
                MyFile_ << "\n";
                MyFile_ << "Second name: " << Second_Name[x];
                MyFile_ << "\n";
                MyFile_ << "Cell number: " << CellNo[x];
                MyFile_ << "\n";
                MyFile_ << "Age: " << Age[x];
                MyFile_ << "\n";
                MyFile_ << "Gender: " << Gender[x];
                MyFile_ << "\n";
                MyFile_ << "Height: " << Height[x];
                MyFile_ << "\n";
                MyFile_ << "Eye colour: " << Eyecolor[x];
                MyFile_ << "\n";
                MyFile_ << "Crime: " << Crime[x];
                MyFile_ << "\n";
                MyFile_ << "Punishment Months: " << Punishmentmonths[x];
                MyFile_ << "\n";
                MyFile_ << "\n";
                c++;
            }
        }
        if (c == 0)
        {

            MyFile_ << "\n\t\t\t\t";
            MyFile_ << "No prisoner Present";
            MyFile_ << "\n";
            MyFile_ << "\t\t\t\t\t";
        }
        MyFile_.close();
        break;
    default:
        cout << "Invalid choice";
        break;
    }

    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "\n";
    cout << "\t\t\t\t\t";
    cout << "Press 1 to return : ";
    scanf("%d", &s);
    if (s == 1)
    {
        Prison::Afterlogin();
    }
}

void Prison ::Afterlogin()
{
    int a, c;
    int v;
    do
    {
        v = 0;
        system("cls");
        Time();
        cout << "\n\n\n";
        cout << "\t\t\t\t---------------------------------------------------------------------------\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     1)   New prisoner entry                             |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     2)   Prisoner details                               |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     3)   Attendace prisoner                             |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     4)   Release prisoner                               |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     5)   Search prisoner                                |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     6)   Prison File                                    |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     7)   Logout                                         |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                     8)   Exit                                           |\n";
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t|                                                                         |\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\t\t\t\t---------------------------------------------------------------------------\n";
        for (a = 0; a <= 100000000; a++)
        {
        }
        cout << "\n";
        cout << "\t\t\t\t\t\t\t";
        cout << "\n";
        cout << "\t\t\t\t\t\t\t";
        cout << "Enter your choice : ";
        cin >> c;
        switch (c)
        {
        case 1:
            Prison ::SetData();
            break;
        case 2:
            Prison ::Details();
            break;
        case 3:
            Prison ::Attendance();
            break;
        case 4:
            Prison ::Release();
            break;
        case 5:
            Prison ::SearchPrison();
            break;
        case 6:
            Prison::PrisonFile();
            break;
        case 7:
            Prison::Logout();
            break;
        case 8:
            Prison::Exit();
            break;
        default:
            cout << "\n\t\t\t\tInvalid choice\n";
            cout << "\t\t\t\tPress 1 to return : ";
            cin >> v;
        }
    } while (v == 1);
}

void Prison ::Exit()
{
    system("cls");
    Time();
    cout << "\n\n\n\n\n\n\t\t\t\t\t\t";
    cout << "Thank you!!";
    cout << "\n\n\n\n\n\n\t\t\t\t\t\t";
    getch();
}

void Date()
{
    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";
}

void Time()
{
    time_t curr_time;
    curr_time = time(NULL);

    tm *tm_local = localtime(&curr_time);
    cout << "Time : " << tm_local->tm_hour << ":" << tm_local->tm_min << ":" << tm_local->tm_sec << endl;
}

void FrontPage()
{
    int process = 0;
    system("cls");
    Time();
    Date();
    cout << "\n";
    int a;
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    ----------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    |   PRISON STATION MANAGEMENT SYSTEM   |\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\t\t\t\t    ----------------------------------------\n";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "\n\n";
    cout << "\t\t\t\t";
    for (a = 0; a <= 100000000; a++)
    {
    }
   
    cout << "Mini Project   ";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << ":";
    for (a = 0; a <= 100000000; a++)
    {
    }
    cout << "   Prison 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 < 15; process++)
    {
        for (int a = 0; a <= 100000000; a++)
        {
        }
        cout << ".";
    }
}

int main()
{
    Prison a;

    FrontPage();
    a.Login();
    return 0;
}

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), string.h (string manipulation), windows.h, fstream, ctime.
  • Now we will declare functions – FrontPage()- for Front Page Or Main Page, void Date() – To get Date, void Time() – To display time.
  • We will be creating a class called Prison which will have private data members contai9ning details of the prisoners such as First name, second name, gender, cell number, age, height, eye color, crime and punishment months.
  • We will create public member functions and define them functions outside the class using scope resolution operator.-
  • SetData() function sets data of the prisoners. It first clears the screen. It prompts the user to add prisoner’s information duch as first and second name, gender, age, height, eyecolor, crime, punishment months, cell number.
  • Details() function gets details of the prisoners. It displays the prisoner’s information in a tabular form.
  • Afterlogin() function will get the user to after login page OR Menu function. It will display the menu options on the console. We will use the switch case to select between the menu options.
  • Attendance() function is used for storing attendance of the prisoners. It records the attendance details of the prisoners in the cell. If the punishment months of a prisoner gets completed then the prisoner is ready for the release.
  • Release() function release the prisoners by entering the cell block of the prisoner, name. We will check the punishment months for the release, if they are completed then we release the prisoner by pressing 1, else prisoner is not released. We will use if else control statement for the functionality.
  • SearchPrison() function search Prison for a prisoner. The user will be asked to enter the prisoner cell id to be searched. Then details will be displayed.
  • PrisonFile() function will ask user in which format you want to open your prison file? The file format available are – txt file, html file, word file. We will use switch cases for the option selection between file formats.
  • Logout() function first clears the screen and prints ‘logging out’. It logs out of the account and calls the login function to display the login screen for other account to login.
  • Exit() function will exit from the program. It will clear the screen first and then display the thankyou message.
  • Login() function declares variables to store login information such as username, password and etc. We will use do while loop and for loops, if else if statements inside for the functionality.
  • The Date() and Time() function will display the local date and time.
  • The FrontPage() function will first clear the screen and then call time and date functions to display time and date. Then will use for loops for the functionality of the process.
  • The main() function will have the object the class Prison and the  call the functions to start the program.
  • This sums up our project of Prison Management System using C++.

Simple Chatbot using C++ (With Source Code)

Final Output:-

Here is an example to show how this project works.

Prison Management System using C++

Prison Management System using C++

Prison Management System using C++

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

Selection option 2:

Prison 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.

Creating a School Fees Enquiry System using C++ (With Source Code)

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

Thank you.

Happy Reading! 🙂

ADVERTISEMENT

Follow: CodeWithRandom

ADVERTISEMENT



Leave a Reply