You are currently viewing Personal Diary Management System using C++ (With Source Code)

Personal Diary Management System using C++ (With Source Code)

Personal Diary Management System using C++ (With Source Code)

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

Personal Dairy Management System
Using C++Personal Dairy Management System
Using C++

A Personal Diary Management System implemented in C++ programming language is a simple software for a personal diary entries. It is built on the idea of saving and generating all of the user’s stories. After passing through the login system, the user may add, read, edit, and delete stories. In order to see, amend, or delete the story, the user must first supply the password. The entire project was created in the ‘C++’ programming language, and several variables and strings were employed in its creation. The users will find this project simple to use and comprehend.

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

This project is user-friendly and may be tailored to your specific requirements. The system has a straightforward capability for storing your personal diary recordings. The project has a basic code script that is easy to learn and understand.

Features Of the System:

  1. The system contains a Login System which lets the user access it only after the correct password has been entered.
  2. The system provides an option to edit the pre-defined password.
  3. A user in the personal diary can Add a story,
  4. View a story or stories
  5. Edit a story
  6. Remove a Story

Overview of the UI:

  • Main Menu of the Personal Diary:
***********************************
DAILY DIARY MANAGEMENT SYSTEM
***********************************
MAIN MENU:
ADD STORY
VIEW STORY
EDIT STORY
DELETE STORY
EDIT PASSWORD
EXIT
ENTER YOUR CHOICE:
  • if wrong choice is entered:
YOU ENTERED WRONG CHOICE..
PRESS ANY KEY TO TRY AGAIN

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.

Personal Dairy Management System  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.

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int password();
void addrecord();
void viewrecord();
void editrecord();
void editpassword();
void deleterecord();

struct record
{
    char time[6];
    char name[30];
    char place[25];
    char duration[10];
    char note[500];
} ;

int login(){
   string pass ="";
   char ch;
   cout << "\n\n\n\n\n\t\t\t\t     Personal Diary Management";
   cout << "\n\n\n\n\n\t\t\t\t\tEnter Password:";
   ch = _getch();
   while(ch != 13){//character 13 is enter
      pass.push_back(ch);
      cout << '*';
      ch = _getch();
   }
   if(pass == "pass"){
      cout << "\n\n\nAccess Granted \n";
      system("PAUSE");
      system("CLS");
      int main();
   }else{
      cout << "\nAccess Aborted...\n";
      system("CLS");
      login();
   }
}


int main()
{
    login();
    int ch;
    cout<<"\n\n\t***********************************\n";
    cout<<"\t  *DAILY DIARY MANAGEMENT SYSTEM*\n";
    cout<<"\t***********************************";
    while(1)
    {
        cout<<"\n\n\t\tMAIN MENU:";
        cout<<"\n\n\tADD STORY\t[1]";
        cout<<"\n\tVIEW STORY\t[2]";
        cout<<"\n\tEDIT STORY\t[3]";
        cout<<"\n\tDELETE STORY\t[4]";
        cout<<"\n\tEDIT PASSWORD\t[5]";
        cout<<"\n\tEXIT\t\t[6]";
        cout<<"\n\n\tENTER YOUR CHOICE:";
        cin>>ch;

        switch(ch)
        {
        case 1:
            addrecord();
            break;
        case 2:
            viewrecord();
            break;
        case 3:
            editrecord();
            break;
        case 4:
            deleterecord();
            break;
        case 5:
            editpassword();
            break;
        case 6:
            cout<<"\n\n\t\tTHANK YOU FOR USING THE SOFTWARE ";
            getch();
            exit(0);
        default:
            cout<<"\nYOU ENTERED WRONG CHOICE..";
            cout<<"\nPRESS ANY KEY TO TRY AGAIN";
            getch();
            break;
        }
        system("cls");
    }
    return 0;
}
void addrecord( )
{
    system("cls");
    FILE *fp ;
    char another = 'Y' ,time[10];
    struct record e ;
    char filename[15];
    int choice;
    cout<<"\n\n\t\t***************************\n";
    cout<<"\t\t* WELCOME TO THE MENU *";
    cout<<"\n\t\t***************************\n\n";
    cout<<"\n\n\tENTER DATE OF YOUR RECORD:[yyyy-mm-dd]:";
    fflush(stdin);
    gets(filename);
    fp = fopen (filename, "ab+" ) ;
    if ( fp == NULL )
    {
        fp=fopen(filename,"wb+");
        if(fp==NULL)
        {
            cout<<"\nSYSTEM ERROR...";
            cout<<"\nPRESS ANY KEY TO EXIT";
            getch();
            return ;
        }
    }
    while ( another == 'Y'|| another=='y' )
    {
        choice=0;
        fflush(stdin);
        cout<< "\n\tENTER TIME:[hh:mm]:";
        cin>>time;
        rewind(fp);
        while(fread(&e,sizeof(e),1,fp)==1)
        {
            if(strcmp(e.time,time)==0)
            {
                cout<<"\n\tTHE RECORD ALREADY EXISTS.\n";
                choice=1;
            }
        }
        if(choice==0)
        {
            strcpy(e.time,time);
            cout<<"\tENTER NAME:";
            fflush(stdin);
            gets(e.name);
            fflush(stdin);
            cout<<"\tENTER PLACE:";
            gets(e.place);
            fflush(stdin);
            cout<<"\tENTER DURATION:";
            gets(e.duration);
            fflush(stdin);
            cout<<"\n\tEXPLAIN THE INCIDENT :";
            gets(e.note);
            fwrite ( &e, sizeof ( e ), 1, fp ) ;
            cout<<"\nYOUR RECORD IS ADDED...\n";
        }
        cout<<"\n\tADD ANOTHER STORY...(Y/N) "  ;
        fflush ( stdin ) ;
        another = getchar( ) ;
    }
    fclose ( fp ) ;
    cout<<"\n\n\tPRESS ANY KEY TO EXIT...";
    getch();
}
void viewrecord( )
{
    FILE *fpte ;
    system("cls");
    struct record customer ;
    char time[6],choice,filename[14];
    int ch;
    cout<<"\n\n\t\t*******************************\n";
    cout<<"\t\t* HERE IS THE VIEWING MENU *";
    cout<<"\n\t\t*******************************\n\n";
    choice=password();
    if(choice!=0)
    {
        return ;
    }
    do
    {
        cout<<"\n\tENTER THE DATE OF RECORD TO BE VIEWED:[yyyy-mm-dd]:";
        fflush(stdin);
        gets(filename);
        fpte = fopen ( filename, "rb" ) ;
        if ( fpte == NULL )
        {
            puts ( "\nTHE RECORD DOES NOT EXIST...\n" ) ;
            cout<<"PRESS ANY KEY TO EXIT...";
            getch();
            return ;
        }
        system("cls");
        cout<<"\n\tHOW WOULD YOU LIKE TO VIEW:\n";
        cout<<"\n\t1.WHOLE STORY OF THE DAY.";
        cout<<"\n\t2.STORY OF FIX TIME.";
        cout<<"\n\t\tENTER YOUR CHOICE:";
        cin>>ch;
        switch(ch)
        {
        case 1:
            cout<<"\nTHE WHOLE STORY FOR  IS:"<<filename;
            while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
            {
                cout<<"\n";
                cout<<"\nTIME:"<<customer.time;
                cout<<"\nMEETING WITH:"<<customer.name;
                cout<<"\nMEETING AT:"<<customer.place;
                cout<<"\nDURATION:"<<customer.duration;
                cout<<"\nNOTE:"<<customer.note;
                cout<<"\n";
            }
            break;
        case 2:
            fflush(stdin);
            cout<<"\nENTER TIME:[hh:mm]:";
            gets(time);
            while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
            {
                if(strcmp(customer.time,time)==0)
                {
                    cout<<"\nYOUR RECORD IS:";
                    cout<<"\nTIME:"<<customer.time;
                    cout<<"\nMEETING WITH:"<<customer.name;
                    cout<<"\nMEETING AT:"<<customer.place;
                    cout<<"\nDUARATION:"<<customer.duration;
                    cout<<"\nNOTE:"<<customer.note;
                }
            }
            break;
        default:
            cout<<"\nYOU TYPED SOMETHING ELSE...\n";
            break;
        }
        cout<<"\n\nWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):";
        fflush(stdin);
        scanf("%c",&choice);
    }
    while(choice=='Y'||choice=='y');
    fclose ( fpte ) ;
    return ;
}
void editrecord()
{
    system("cls");
    FILE *fpte ;
    struct record customer ;
    char time[6],choice,filename[14];
    int num,count=0;
    cout<<"\n\n\t\t*******************************\n";
    cout<<"\t\t* WELCOME TO THE EDITING MENU *";
    cout<<"\n\t\t*******************************\n\n";
    choice=password();
    if(choice!=0)
    {
        return ;
    }
    do
    {
        cout<<"\n\tENTER THE DATE OF RECORD TO BE EDITED:[yyyy-mm-dd]:";
        fflush(stdin);
        gets(filename);
        cout<<"\n\tENTER TIME:[hh:mm]:";
        gets(time);
        fpte = fopen ( filename, "rb+" ) ;
        if ( fpte == NULL )
        {
            cout<< "\nRECORD DOES NOT EXISTS:"  ;
            cout<<"\nPRESS ANY KEY TO GO BACK";
            getch();
            return;
        }
        while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
        {
            if(strcmp(customer.time,time)==0)
            {
                cout<<"\nYOUR OLD RECORD WAS AS:";
                cout<<"\nTIME: %s",customer.time;
                cout<<"\nMEETING WITH:"<<customer.name;
                cout<<"\nMEETING AT:"  <<customer.place;
                cout<<"\nDURATION: "  <<customer.duration;
                cout<<"\nNOTE:" <<customer.note;
                cout<<"\n\n\t\tWHAT WOULD YOU LIKE TO EDIT..";
                cout<<"\n1.TIME.";
                cout<<"\n2.MEETING PERSON.";
                cout<<"\n3.MEETING PLACE.";
                cout<<"\n4.DURATION.";
                cout<<"\n5.NOTE.";
                cout<<"\n6.WHOLE RECORD.";
                cout<<"\n7.GO BACK TO MAIN MENU.";
                do
                {
                    cout<<"\n\tENTER YOUR CHOICE:";
                    fflush(stdin);
                    cin>>num;
                    fflush(stdin);
                    switch(num)
                    {
                    case 1:
                        cout<<"\nENTER THE NEW DATA:";
                        cout<<"\nNEW TIME:[hh:mm]:";
                        gets(customer.time);
                        break;
                    case 2:
                        cout<<"\nENTER THE NEW DATA:";
                        cout<<"\nNEW MEETING PERSON:";
                        gets(customer.name);
                        break;
                    case 3:
                        cout<<"\nENTER THE NEW DATA:";
                        cout<<"\nNEW MEETING PLACE:";
                        gets(customer.place);
                        break;
                    case 4:
                        cout<<"\nENTER THE NEW DATA:";
                        cout<<"\nDURATION:";
                        gets(customer.duration);
                        break;
                    case 5:
                        cout<<"ENTER THE NEW DATA:";
                        cout<<"\nNOTE:";
                        gets(customer.note);
                        break;
                    case 6:
                        cout<<"\nENTER THE NEW DATA:";
                        cout<<"\nNEW TIME:[hh:mm]:";
                        gets(customer.time);
                        cout<<"\nNEW MEETING PERSON:";
                        gets(customer.name);
                        cout<<"\nNEW MEETING PLACE:";
                        gets(customer.place);
                        cout<<"\nDURATION:";
                        gets(customer.duration);
                        cout<<"\nNOTE:";
                        gets(customer.note);
                        break;
                    case 7:
                        cout<<"\nPRESS ANY KEY TO GO BACK...\n";
                        getch();
                        return ;
                        break;
                    default:
                        cout<<"\nYOU TYPED SOMETHING ELSE...TRY AGAIN\n";
                        break;
                    }
                }
                while(num<1||num>8);
                fseek(fpte,-sizeof(customer),SEEK_CUR);
                fwrite(&customer,sizeof(customer),1,fpte);
                fseek(fpte,-sizeof(customer),SEEK_CUR);
                fread(&customer,sizeof(customer),1,fpte);
                choice=5;
                break;
            }
        }
        if(choice==5)
        {
            system("cls");
            cout<<"\n\t\tEDITING COMPLETED...\n";
            cout<<"--------------------\n";
            cout<<"THE NEW RECORD IS:\n";
            cout<<"--------------------\n";
            cout<<"\nTIME:"<<customer.time;
            cout<<"\nMEETING WITH:" <<customer.name;
            cout<<"\nMEETING AT:"<<customer.place;
            cout<<"\nDURATION:"<<customer.duration;
            cout<<"\nNOTE:"<<customer.note;
            fclose(fpte);
            cout<<"\n\n\tWOULD YOU LIKE TO EDIT ANOTHER RECORD.(Y/N)";
            cin>>choice;
            count++;
        }
        else
        {
            cout<<"\nTHE RECORD DOES NOT EXIST::\n";
            cout<<"\nWOULD YOU LIKE TO TRY AGAIN...(Y/N)";
            cin>>choice;
        }
    }
    while(choice=='Y'||choice=='y');
    fclose ( fpte ) ;
    if(count==1)
        cout<<"\n%d FILE IS EDITED...\n",count;
    else if(count>1)
        cout<<"\n%d FILES ARE EDITED..\n",count;
    else
        cout<<"\nNO FILES EDITED...\n";
    cout<<"\tPRESS ENTER TO EXIT EDITING MENU.";
    getch();
}

int password()
{
    char pass[15]= {0},check[15]= {0},ch;
    FILE *fpp;
    int i=0,j;
    cout<<"::FOR SECURITY PURPOSE::";
    cout<<"::ONLY THREE TRIALS ARE ALLOWED::";
    for(j=0; j<3; j++)
    {
        i=0;
        cout<<"\n\n\tENTER THE PASSWORD:";
        pass[0]=getch();
        while(pass[i]!='\r')
        {
            if(pass[i]=='\b')
            {
                i--;
                cout<<"\b";
                cout<<" ";
                cout<<"\b";
                pass[i]=getch();
            }
            else
            {
                cout<<"*";
                i++;
                pass[i]=getch();
            }
        }
        pass[i]='\0';
        fpp=fopen("SE","r");
        if (fpp==NULL)
        {
            cout<<"\nERROR WITH THE SYSTEM FILE...[FILE MISSING]\n";
            getch();
            return 1;
        }
        else
            i=0;
        while(1)
        {
            ch=fgetc(fpp);
            if(ch==EOF)
            {
                check[i]='\0';
                break;
            }
            check[i]=ch-5;
            i++;
        }
        if(strcmp(pass,check)==0)
        {
            cout<<"\n\n\tACCESS GRANTED...\n";
            return 0;
        }
        else
        {
            cout<<"\n\n\tWRONG PASSWORD..\n\n\tACCESS DENIED...\n";
        }
    }
    cout<<"\n\n\t::YOU ENTERED WRONG PASSWORD::YOU ARE NOT ALLOWED TO ACCESS ANY FILE::\n\n\tPRESS ANY KEY TO GO BACK...";
    getch();
    return 1;
}

void editpassword()
{
    system("cls");
    cout<<"\n";
    char pass[15]= {0},confirm[15]= {0},ch;
    int choice,i,check;
    FILE *fp;
    fp=fopen("SE","rb");
    if(fp==NULL)
    {
        fp=fopen("SE","wb");
        if(fp==NULL)
        {
            cout<<"SYSTEM ERROR...";
            getch();
            return ;
        }
        fclose(fp);
        cout<<"\nSYSTEM RESTORED...\nYOUR PASSWORD IS 'ENTER'\n PRESS ENTER TO CHANGE PASSWORD\n\n";
        getch();
    }
    fclose(fp);
    check=password();
    if(check==1)
    {
        return ;
    }
    do
    {
        if(check==0)
        {
            i=0;
            choice=0;
            cout<<"\n\n\tENTER THE NEW PASSWORD:";
            fflush(stdin);
            pass[0]=getch();
            while(pass[i]!='\r')
            {
                if(pass[i]=='\b')
                {
                    i--;
                    cout<<"\b";
                    cout<<" ";
                    cout<<"\b";
                    pass[i]=getch();
                }
                else
                {
                    cout<<"*";
                    i++;
                    pass[i]=getch();
                }
            }
            pass[i]='\0';
            i=0;
            cout<<"\n\tCONFIRM PASSWORD:";
            confirm[0]=getch();
            while(confirm[i]!='\r')
            {
                if(confirm[i]=='\b')
                {
                    i--;
                    cout<<"\b";
                    cout<<" ";
                    cout<<"\b";
                    confirm[i]=getch();
                }
                else
                {
                    cout<<"*";
                    i++;
                    confirm[i]=getch();
                }
            }
            confirm[i]='\0';
            if(strcmp(pass,confirm)==0)
            {
                fp=fopen("SE","wb");
                if(fp==NULL)
                {
                    cout<<"\n\t\tSYSTEM ERROR";
                    getch();
                    return ;
                }
                i=0;
                while(pass[i]!='\0')
                {
                    ch=pass[i];
                    putc(ch+5,fp);
                    i++;
                }
                putc(EOF,fp);
                fclose(fp);
            }
            else
            {
                cout<<"\n\tTHE NEW PASSWORD DOES NOT MATCH.";
                choice=1;
            }
        }
    }
    while(choice==1);
    cout<<"\n\n\tPASSWORD CHANGED...\n\n\tPRESS ANY KEY TO GO BACK...";
    getch();
}

void deleterecord( )
{
    system("cls");
    FILE *fp,*fptr ;
    struct record file ;
    char filename[15],another = 'Y' ,time[10];;
    int choice,check;
    cout<<"\n\n\t\t*************************\n";
    cout<<"\t\t* WELCOME TO DELETE MENU*";
    cout<<"\n\t\t*************************\n\n";
    check = password();
    if(check==1)
    {
        return ;
    }
    while ( another == 'Y' )
    {

        cout<<"\n\n\tHOW WOULD YOU LIKE TO DELETE.";
        cout<<"\n\n\t#DELETE WHOLE RECORD\t\t\t[1]";
        cout<<"\n\t#DELETE A PARTICULAR RECORD BY TIME\t[2]";
        do
        {
            cout<<"\n\t\tENTER YOU CHOICE:";
            cin>>choice;
            switch(choice)
            {
            case 1:
                cout<<"\n\tENTER THE DATE OF RECORD TO BE DELETED:[yyyy-mm-dd]:";
                fflush(stdin);
                gets(filename);
                fp = fopen (filename, "wb" ) ;
                if ( fp == NULL )
                {
                    cout<<"\nTHE FILE DOES NOT EXISTS";
                    cout<<"\nPRESS ANY KEY TO GO BACK.";
                    getch();
                    return ;
                }
                fclose(fp);
                remove(filename);
                cout<<"\nDELETED SUCCESFULLY...";
                break;
            case 2:
                cout<<"\n\tENTER THE DATE OF RECORD:[yyyy-mm-dd]:";
                fflush(stdin);
                gets(filename);
                fp = fopen (filename, "rb" ) ;
                if ( fp == NULL )
                {
                    cout<<"\nTHE FILE DOES NOT EXISTS";
                    cout<<"\nPRESS ANY KEY TO GO BACK.";
                    getch();
                    return ;
                }
                fptr=fopen("temp","wb");
                if(fptr==NULL)
                {
                    cout<<"\nSYSTEM ERROR";
                    cout<<"\nPRESS ANY KEY TO GO BACK";
                    getch();
                    return ;
                }
                cout<<"\n\tENTER THE TIME OF RECORD TO BE DELETED:[hh:mm]:";
                fflush(stdin);
                gets(time);
                while(fread(&file,sizeof(file),1,fp)==1)
                {
                    if(strcmp(file.time,time)!=0)
                        fwrite(&file,sizeof(file),1,fptr);
                }
                fclose(fp);
                fclose(fptr);
                remove(filename);
                rename("temp",filename);
                cout<<"\nDELETED SUCCESFULLY...";
                break;
            default:
                cout<<"\n\tYOU ENTERED WRONG CHOICE";
                break;
            }
        }
        while(choice<1||choice>2);
        cout<<"\n\tDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N):";
        fflush(stdin);
        cin>>another;
    }
    cout<<"\n\n\tPRESS ANY KEY TO EXIT...";
    getch();
}


pass – pass

Now let us understand the code:-

  • We will start by writing the header of the code with the required libraries – stdio.h (standard input/output), stdlib.h (memory management),iostream  (input and output stream), conio.h (console input/output), string.h (string manipulation).
  • Now we will give forward declarations for the functions which will be used in this project –
    int password();
    void addrecord();
    void viewrecord();
    void editrecord();
    void editpassword();
    void deleterecord();
  • We will create a structure called ‘record’ using the keyword ‘struct’ which will contain information related to the records of the diary. The arrays in the structure are –
    time[6];
    char name[30];
    char place[25];
    char duration[10];
    char note[500];
  • The login() function will contain the functionality required to create a login system using password. The user will enter a predefined password to get the access. We will initialize a string type variable called pass which will be used to check for the password entered by the user with the predefined password. The password in this system is ‘pass’. You can change it in the source code according to your choice as well. This function will also display the heading on the console – ‘Personal Diary Management’. We will use an if-else control statement to display access granted else aborted if the password entered is something else.
  • The main() function will first display the menu of options to perform in this system – add story, view, edit, delete, edit, exit. The user will enter the choice. We will use a switch case to select among the options to perform.
  • The addrecord() function will let the user add the record of personal diary into the system – providing details like date, time, name, place, duration, and note. It will prompt the user to enter date of record. Instead of filename, write the name of the file text file where you want your records to get stored.
  • The viewrecord() function will allow the user to examine previous diary entries. The user has the option of seeing the complete diary for a certain day or viewing a single entry based on the time. We will use a switch case fore the functionality.
  • The editrecord() function will let the user edit the already existing records. The user needs to provide the current password and then enter a new password. The user can edit the choice of entry they want.
  • The password() function will let the user enter the password to get access to the system. We will be declaring and initializing 2 char type arrays – pass[] – to store the entered password and check[] – to store the predefined password stored in a file. To enter the password, only 3 trials are given. The user will enter the password and it will get assigned to pass[]. It then uses fpp=fopen(“SE”,”r”) to open a file named “SE” in read mode. The password is believed to be saved in this file. If the file does not exist, an error message is displayed and a 1 is returned to indicate an error. We will be using strcmp(pass, check), the inputted password is compared to the decrypted password stored in the check array. If the passwords match, it shows an access permitted message and returns 0 to indicate that authentication was successful.
  • The edit() password function allows the user to edit the password. The user needs to provide the current password and then enter a new password.
  • The deleterecord() function allows the user to delete the password. The user has the option of deleting the whole diary for a certain day or deleting a single entry based on the time. We will be using switch case in this function inside the loops. The fflush() predefined function is used to flush the output buffer of the stream.
  • This sums up our project of Creating Personal Diary Management System using C++.

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

Final Output:-

Here is an example to show how this project works.

Personal Dairy Management System
Using C++

Personal Dairy Management System
Using C++

Personal Dairy Management System
Using C++

Personal Dairy Management System
Using C++

Personal Dairy 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.

Simple RPG Monster Game 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! 🙂

Follow: CodewithRandom



Leave a Reply