Coding Practice
Showing posts with label Projects. Show all posts
Showing posts with label Projects. Show all posts

Project - Linux Toolbox | Based on Shell Script

Table of Content

Chapter 1 Introduction

  1.1 Introduction

  1.2 Design Goals/Objective

Chapter 2 Design/Development/Implementation of the Project

  2.1 Design

  2.2 Code Implementation

Chapter 3 Performance Evaluation

  3.1 Simulation Environment/ Simulation Procedure

  3.2 Results and Discussions

  3.3 Analysis and Outcome

  3.4 Limitations

Chapter 4 Conclusion

  4.1 Introduction

  4.2 Practical Implications

  4.3 Scope of Future Work

References

Chapter 1

Introduction

1.1 Introduction

Linux Toolbox is a tool for Linux operating systems, which allow to check the different type of system information. For example - date, time, device owner, disk usages, memory usages, CPU usages and etc. Another feature of Linux Toolbox is - it will show the current monthly calendar for any year, it can manage a huge of contact information, and it can create a notebook.

1.2 Design Goals/Objective

The sole intention behind the consideration of this project is to generate and manage to show some system information. This project has been developed considering note and contact information keeping the context of the user in mind. Here, the data has been stored in a few text files in the storage.

Chapter 2

Design/Development/Implementation of the Project

2.1 Design

To develop Linux Toolbox, we use Visual Studio Code IDE for code edit. The Linux Toolbox is a simple GUI-based application that has been developed in Shell Script. It is allowed to show system information, enables a store of notebook and contact information. Those are essentially databases that track all information for a user and a user can avail the benefits of using this application. Here, linux_toolbox.sh is the main file. There is also have a file calendar.sh that can show a month of calendar for the user.

2.2 Code Implementation

In this application, users can sign-up, log-in and see the monthly calendar. Also, users can use notebooks and add favorite contact information. We worked with Bash language and use Graphical User Interface via the YAD library. In the case of Bash/Shell Script, we have used some functions such as calendar, home, notebook, view_all_note, contact, and etc which have been used to reduce the code space. Click below to jump in the source code-

Source Code - Linux Toolbox
#!/bin/bash

FILE=$(pwd)/admin.log
LOGGEDIN=$(pwd)/loggedin.log

# bash functions start
#calendar window
function calendar(){
   yad --center --borders=10 --width=420 --title="Linux Toolbox - Calendar" --calendar --button=Back:0

   if [ ${?} -eq 252 ]; then
       echo "Linux Toolbox closed by user"
       exit
   fi
}

function view_all_note() {
    echo "View all note"

    # Get all note from file
    note_file=$(pwd)/notebook.txt

    if [ -f "$note_file" ]; then
        note_text=$(cat notebook.txt)
        notebook=$(yad --scroll --width=450 --height=500 --title="Linux Toolbox - Notebook" --borders=10 --center --separator="ㅤ" \
        --text-align=center \
        --text="<span><b><big><big>My Notes</big></big></b></span>" \
        --form \
        --field="$note_text":LBL \
        --button="Back:0" \
        )
        btn_click=$?

        if [ $btn_click == 0 ]; then
            echo "Back to Notebook"
        elif [ $btn_click == 252 ]; then
            echo "Linux Toolbox closed by user"
            exit
        fi
    else
        echo "No note found"
        notebook=$(yad --scroll --width=450 --height=500 --title="Linux Toolbox - Notebook" --borders=10 --center --separator="ㅤ" \
        --text-align=center \
        --text="<span><b><big><big>My Notes</big></big></b></span>" \
        --form \
        --field="No note found":LBL \
        --button="Back:0" \
        )
        btn_click=$?

        if [ $btn_click == 0 ]; then
            echo "Back to Notebook"
        elif [ $btn_click == 252 ]; then
            echo "Linux Toolbox closed by user"
            exit
        fi
    fi
}

function notebook(){

    while :
    do
        notebook=$(yad --width=450 --height=500 --title="Linux Toolbox - Notebook" --borders=10 --center --separator="ㅤ" \
        --text-align=center \
        --text="<span><b><big><big>Create Your Note</big></big></b></span>" \
        --form --field="<b>Title</b>": \
        --field="":TXT \
        --button="Add:2" \
        --button="View:3" \
        --button="Back:0" \
        )
        btn_click=$?

        if [ $btn_click == 0 ]; then
            echo "Back to home"
            break
        elif [ $btn_click == 2 ]; then
            title=$(echo $notebook | awk -F "ㅤ" '{print $1}')
            notebook=$(echo $notebook | awk -F "ㅤ" '{print $2}')
            break="\n----------------------------------------------------------------------------------------------------------\n"
            echo "Title: $title\nNote: $notebook $break" >> notebook.txt
            echo "Note added"
        elif [ $btn_click == 3 ]; then
            echo "View Note"
            view_all_note
        fi
    done
}

# contact window start
function add_contact(){

    contact_value=$(yad --form --center --borders=10 --width=380 --height=280 --title="Linux Toolbox" --separator='ㅤ' \
    --text-align=center --text="<span><b><big><big>Add Contact</big></big></b></span>"\
    --field="  <b>Name:</b>":LBL \
    --field="" \
    --field="  <b>Phone:</b>":LBL \
    --field="" \
    --field="  <b>Email:</b>":LBL \
    --field="" \
    --button=Add:0 \
    --button=Back:1 \ ) valid=${?}

    code=${?}

    if [ $code == 1 ]; then
        echo "Back to the contact window"
    elif [ $code == 0 ]; then
        echo "$contact_value"
        echo "Add contact"

        name=$(echo $contact_value | awk -F "ㅤ" '{print $2}')
        phone=$(echo $contact_value | awk -F "ㅤ" '{print $4}')
        email=$(echo $contact_value | awk -F "ㅤ" '{print $6}')
        break="------------------------------------------------"
        echo -e "Name: $name | Phone: $phone | Email: $email\n" >> contact_list.log
        add_contact
    fi
}

function phone_number_not_found(){
    echo "Phone number not found"
    $(yad --center --borders=10 --width=350 --height=300 --title="Linux Toolbox" --text="<span><b><big><big>Phone number not found</big></big></b></span>" \
    --button="Back":1 \ )
    code=${?}

    if [ $code == 1 ]; then
        echo "Back to home window"
    elif [ $code == 252 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi
}

function update_contact(){

    echo "Update contact"

    update_string=$(yad --form --center --borders=10 --width=350 --height=300 --title="Linux Toolbox" --separator='ㅤ' --text-align=center --text="<span><b><big><big>Update Contact</big></big></b></span>" \
    --field="<b>Old Phone:</b>":LBL \
    --field="" \
    --field="<b>New Name:</b>":LBL \
    --field="" \
    --field="<b>New Phone:</b>":LBL \
    --field="" \
    --field="<b>New Email:</b>":LBL \
    --field="" \
    --button="Update":0 \
    --button="Back":1 \ )

    code=${?}

    if [ $code == 1 ]; then
        echo "Back to home window"
    elif [ $code == 0 ]; then
        echo "Update string: $update_string"
        
        old_phone=""
        

        entry_phone=$(echo $update_string | awk -F "ㅤ" '{print $2}')
        full_string=$(grep -i "$entry_phone" contact_list.log)
    
        old_name=$(echo $full_string | awk '{print $2}')
        old_phone=$(echo $full_string | awk '{print $5}')
        old_email=$(echo $full_string | awk '{print $8}')

        echo "Full string: $full_string"
        echo "Old phone: $old_phone"
        echo "Entry phone: $entry_phone"

        if [ ! -z "$old_phone" ]; then
            if [ $entry_phone == $old_phone ]; then
                echo "Phone number found"

                new_name=$(echo $update_string | awk -F "ㅤ" '{print $4}')
                new_phone=$(echo $update_string | awk -F "ㅤ" '{print $6}')
                new_email=$(echo $update_string | awk -F "ㅤ" '{print $8}')

                if [ ! -z "$new_name" ]; then
                    sed -i "s/$old_name/$new_name/g" contact_list.log
                fi
                if [ ! -z "$new_phone" ]; then
                    sed -i "s/$old_phone/$new_phone/g" contact_list.log
                fi
                if [ ! -z "$new_email" ]; then
                    sed -i "s/$old_email/$new_email/g" contact_list.log
                fi
                echo "Contact Updated"
            else
                phone_number_not_found
            fi
        else
            phone_number_not_found
        fi
    elif [ $code == 252 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi
}

function view_contact(){
    
    echo "View contact"
    v_contact=$(nl -s '. ' -w 1 contact_list.log)

    $(yad --form --center --borders=10 --width=350 --height=300 --title="Linux Toolbox" --separator=' ' --text-align=center --scroll --text="<span><b><big><big>Contact List</big></big></b></span>"\
    --field="":LBL \
    --field="$v_contact":LBL \
    --button="Add":1 \
    --button="Update":2 \
    --button="Search":3 \
    --button="Delete":4 \
    --button="Back":0 \ )

    code=${?}
    
    if [ $code == 0 ]; then
        echo "Back to manage contact window"
    elif [ $code == 1 ]; then
        echo "Add contact"
        add_contact
    elif [ $code == 2 ]; then
        echo "Update contact"
        update_contact
    elif [ $code == 3 ]; then
        echo "Search contact"
        search_contact
    elif [ $code == 4 ]; then
        echo "Delete contact"
        delete_contact
    elif [ $code == 252 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi

}

function search_contact (){

    echo "Search contact"

    search_field=$(yad --form --center --borders=10 --width=350 --height=300 --title="Linux Toolbox" --separator=' ' --text-align=center --text="<span><b><big><big>Search Contact</big></big></b></span>" \
    --field="":LBL \
    --field="" \
    --button="Search":0 \
    --button="Back":1 \ ) code=${?}

    code=${?}

    if [ $code == 1 ]; then
        echo "Back to home window"
    elif [ $code == 0 ]; then
        echo "Search query: $search_field"
        contact_find $search_field
    elif [ $code == 252 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi
}

function contact_find {
    echo "Find contact"
    search=$(grep -i $1 contact_list.log)
    find_field=$(yad --form --center --borders=10 --width=450 --height=300 --scroll --title="Linux Toolbox" --separator=' ' --text-align=center --text="<span><b><big><big>Search Contact</big></big></b></span>"\
    --field="<b>Search Query:</b> $1\n\n<b>Result:</b>":LBL \
    --field="$search":LBL \
    --button="Back":1 \ ) code=${?}

    code=${?}

    if [ $code == 1 ]; then
        echo "Back to home window"
    elif [ $code == 252 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi
}

function delete_contact(){

    delete_string=$(yad --form --center --borders=10 --width=350 --height=300 --title="Linux Toolbox" --separator='ㅤ' --text-align=center --text="<span><b><big><big>Delete Contact</big></big></b></span>" \
    --field="<b>Enter Phone Number:</b>":LBL \
    --field="" \
    --button="Delete":0 \
    --button="Back":1 \ ) code=${?}


    if [ $code == 1 ]; then
            echo "Back to home window"
    elif [ $code == 0 ]; then

        echo "Delete string: $delete_string"
        
        entry_phone=$(echo $delete_string | awk -F "ㅤ" '{print $2}')
        full_string=$(grep -i "$entry_phone" contact_list.log)

        delete_via_phone=$(echo $full_string | awk '{print $5}')

        echo "Delete row: $delete_via_phone"

        if [ ! -z "$delete_via_phone" ]; then
                if [ $entry_phone == $delete_via_phone ]; then
                
                    sed -i -e "/$delete_via_phone/d" contact_list.log
                    echo "Contact deleted"
                else
                    phone_number_not_found
                fi
        else
            phone_number_not_found
        fi
    fi
}
# contact window end

function contact(){
    
    while :
    do
        contact=$(yad --form --center --borders=10 --width=350 --height=300 --title="Linux Toolbox" --separator=' ' --text-align=center --text="<span><b><big><big>Manage Contacts</big></big></b></span>"\
        --field="":LBL \
        --field="<b>Add:</b> Add contact information. i.e: Name, Email Address, and Phone Number.":LBL \
        --field="<b>Update:</b> Update a specific contact.":LBL \
        --field="<b>View:</b> View the contact list after adding one or more contact to list.":LBL \
        --field="<b>Search:</b> Search a specific contact.":LBL \
        --field="<b>Delete:</b> Delete a specific contact.":LBL \
        --button="Add":1 \
        --button="Update":2 \
        --button="View":3 \
        --button="Search":4 \
        --button="Delete":5 \
        --button="Back":0 \ ) code=${?}

        code=${?}
        
        if [ $code == 0 ]; then
            echo "Contact window closed by user"
            ./linux_toolbox.sh
            exit
        elif [ $code == 1 ]; then
            echo "Add contact"
            add_contact
        elif [ $code == 2 ]; then
            echo "Update contact"
            update_contact
        elif [ $code == 3 ]; then
            echo "View contact"
            view_contact
        elif [ $code == 4 ]; then
            echo "Search contact"
            search_contact
        elif [ $code == 5 ]; then
            echo "Delete contact"
            delete_contact
        elif [ $code == 252 ]; then
            echo "Linux Toolbox closed by user"
            exit
        fi
    done
}

function home(){

    date=$(date +'%A %B %d, %Y')
    time=$(date +'%l:%M:%S %p')
    user=$(whoami)
    email=$(awk -F ":" '{print $1}' admin.log)
    # cmd: lscpu 
    #memory_usage=$(free | awk 'FNR==2 {print $3/(1024*1024),"/ "$2/(1024*1024)" GB"}')
    swap_usage=$(free | awk 'FNR==3 {print $3/(1024*1024),"/ "$2/(1024*1024)" GB"}')
    free_disk=$(df | awk 'FNR==4 {print $3/(1024*1024),"/ "$2/(1024*1024)" GB"}')

    total_memory=$(cat /proc/meminfo | awk 'FNR==1 {print $2/(1024*1024)}')
    availabe_memory=$(cat /proc/meminfo | awk 'FNR==3 {print $2/(1024*1024)}')
    memory_usage=$(echo "$total_memory - $availabe_memory" | bc)

    swap_usage=$(free | awk 'FNR==3 {print $3/(1024) "  MB","/ "$2/(1024*1024)" GB"}')
    disk_usage=$(df | awk 'FNR==4 {print $3/(1024*1024) " GB","/ "$2/(1024*1024)" GB"}')

    processor=$(cat /proc/cpuinfo | awk -F ": " 'FNR==5 {print $2}')
    cache_size=$(cat /proc/cpuinfo | awk -F ": " 'FNR==9 {print $2}')
    total_processor=$(cat /proc/cpuinfo | grep processor | wc -l)
    os_type=$(lscpu | awk 'FNR==2 {print $4}')
    os_support=$(lscpu | awk 'FNR==2 {print $3,$4}')
    cpu_speed=$(lscpu | awk 'FNR==16 {print $3}' | sed 's/\..*//')
    cpu_min_speed=$(lscpu | awk 'FNR==18 {print $4}' | sed 's/\..*//')
    cpu_max_speed=$(lscpu | awk 'FNR==17 {print $4}' | sed 's/\..*//')
    total_task=$(ps -e | wc -l)

    yad --title="Linux Toolbox" --center --borders=10 --width=450 --height=500 --text-align=center --separator="" --text="<span><b><big><big>System Info</big></big></b></span>" \
    --field="":LBL \
    --form \
    --field="<b><u>Basic Info</u></b>":LBL \
    --field="<b>Date:</b> $date":LBL \
    --field="<b>Time:</b> $time":LBL \
    --field="<b>Username:</b> $user":LBL \
    --field="<b>Email:</b> $email":LBL \
    --field="":LBL \
    --field="<b><u>Memory Info</u></b>":LBL \
    --field="<b>Memory Usage: </b>$memory_usage GB / $total_memory GB":LBL \
    --field="<b>Memory Available: </b>$availabe_memory GB":LBL \
    --field="<b>Swap Usage: </b>$swap_usage":LBL \
    --field="<b>Disk Usage: </b>$disk_usage":LBL \
    --field="":LBL \
    --field="<b><u>CPU Info</u></b>":LBL \
    --field="<b>Processor: </b>$processor × $total_processor":LBL \
    --field="<b>OS Type: </b>$os_type":LBL \
    --field="<b>OS Support: </b>$os_support":LBL \
    --field="<b>Cache Size: </b>$cache_size":LBL \
    --field="<b>CPU Speed: </b>$cpu_speed MHz":LBL \
    --field="<b>CPU Min Speed: </b>$cpu_min_speed MHz":LBL \
    --field="<b>CPU Max Speed: </b>$cpu_max_speed MHz":LBL \
    --field="<b>Total Task: </b>$total_task":LBL \
    --field="Calendar":FBTN "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "./calendar.sh" \
    --button="Notebook":2 \
    --button="Contact":3 \
    --button="Refresh":1 \
    --button="Log out":4 \
    --button="Exit":0
    code=${?}

    if [ $code == 0 ]; then
        echo "Linux Toolbox closed by user"
        exit
    elif [ $code == 1 ]; then
        echo "Refresh Date: $date $time"
    elif [ $code == 2 ]; then
        echo "Notebook window"
        notebook
    elif [ $code == 3 ]; then
        echo "Contact window"
        contact
    elif [ $code == 4 ]; then
        echo "Logged out"
        rm loggedin.log
        ./linux_toolbox.sh
        exit
    elif [ $code == 252 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi
}

export -f calendar home notebook view_all_note contact add_contact view_contact search_contact contact_find update_contact phone_number_not_found delete_contact
# bash functions end

if [ -f "$FILE" ]
then
    while :
    do
        
        if [ -f "$LOGGEDIN" ]
        then
            old_usr_pass=$(cat admin.log)
            log_usr_pass=$(cat loggedin.log)

            if [ $old_usr_pass == $log_usr_pass ]
            then
                # If the user has already logged in, redirected in home page
                echo "User already logged in"
                home
            else
                rm loggedin.log
                echo "User not logged in"
            fi
        else
            # login window start
            echo "Login window..."
            # login window
            login=$(yad --form --center --borders=10 --width=400 --height=300 --title="Linux Toolbox - Login" --separator=' ' \
                --button="Calendar":"bash -c calendar" \
                --button=Exit:1 \
                --button=Login:0 \
                --field="Email":\
                --field="Password":\') valid=${?}

            if [ $valid -eq 0 ]; then

                email=$(echo $login | awk '{print $1}') 
                password=$(echo $login | awk '{print $2}')

                echo "Email = $email"

            elif [ $valid -eq 1 ]; then
                echo "Linux Toolbox closed by user"
                exit
            fi
            # login window end

            echo -e "$email:$password" >> temp.log

            old_usr_pass=$(cat admin.log)
            crnt_usr_pass=$(cat temp.log)

            if [ $old_usr_pass == $crnt_usr_pass ]
            then
                rm temp.log
                echo "Login Successful"
                echo "$email:$password" >> loggedin.log
                # login success window start
                home
                # login success window end
            else
                rm temp.log
                # login failed window start
                echo "Login Failed!"
                echo "Wrong email or password"
                # login failed window end
            fi

        fi

    done

else
    # create admin.log file start
    echo "Signup window..."

    # signup window
    signup=$(yad --form --center --borders=10 --width=350 --height=300 --title="Linux Toolbox - Signup" --separator=' ' --text-align=center --text="<span><b><big><big>Signup</big></big></b></span>"\
        --field="":LBL \
        --button="Calendar":"bash -c calendar" \
        --button=Exit:1 \
        --button=Signup:0 \
        --field="Email":\
        --field="Password":\') valid=${?}

    if [ $valid -eq 0 ]; then

        email=$(echo $signup | awk '{print $1}') 
        password=$(echo $signup | awk '{print $2}')

        echo "Email = $email"
        # echo "Password = $password"

        echo "$email:$password" >> admin.log
        # create admin.log file end

        ./linux_toolbox.sh

    elif [ $valid -eq 1 ]; then
        echo "Linux Toolbox closed by user"
        exit
    fi
    
fi
Source Code - Calendar
echo "Calendar window"

yad --center --borders=10 --width=420 --title="Linux Toolbox - Calendar" --calendar --button=Back:0

if [ ${?} -eq 252 ]; then
    echo "Linux Toolbox closed by user"
    exit
fi

Chapter 3 Performance

Evaluation

3.1 Simulation

We have been able to meet the goals we set for ourselves in this project. Our code worked properly and was able to run Linux Toolbox. Also, the additional functions we added for user interaction all worked the way we initially expected. Each step along the way we tested our code to make sure everything was properly mapped.

3.2 Results and Discussions

After running Linux Toolbox, it will show the Sign-up window for the first time. Once the user has successfully signed up, the user will be shown a login window. And then the user needs to log in to use Linux Toolbox. Here users can use a blank email and password when signing up.

Sign-up window
Sign-in window

Figure-1: Sign-up and Login Window

After successful login, users will be able to view system information, add notebooks, and manage contact information.

System Information Window

Figure-2: System Information Window

Calendar Window

Figure-3: Calendar Window

Create Notebook Window

Figure-4: Create Notebook Window

Notebook Window

Figure-5: Notebook Window

Manage Contacts Window

Figure-6: Manage Contacts Window

Update Contacts Window
Search Contacts Window

Figure-7: Update and Search Contacts Window

Search Contacts Window

Figure-8: Search Contacts Window

Figure-9: Contact List Window

3.3 Analysis and Outcome

Our goal was to see the monthly calendar, add notes, manage contact, and view system information. In this project, our code worked properly and was able to successfully run Linux Toolbox. Also, the additional functions we added for user interaction all worked the way we initially expected. Each step along the way we tested our code to make sure everything was properly mapped.

3.4 Limitations

Although Linux Toolbox runs properly, there is some limitation for this application.

  1. In the Manage Contact part, the user can add multiple strings like a name but can’t update multiple strings as a name.
  2. The user can’t modify/update, search and delete Notebook.
  3. There may be other bugs in the Linux toolbox.

Chapter 4

Conclusion

4.1 Introduction

In this project, we gained a lot of knowledge and experience working with the Linux operating system. We learned how to work Bash language. Also, we learned more about the basic principles of Linux application. Our team members have made improvements in various areas such as developing a structured information pathway for all types of software and understanding more about state machines. Although this is a YAD base project, it was a great experience in developing software. The principle behind constructing a Linux Toolbox is to effectively retrieve and implement any information. All the information related to a particular people can be linked and archived only to be retrieved later when they are required most.

4.2 Practical Implications

Linux Toolbox is one of the useful applications used to show the system information. This type of software can be used to note down user information and create contact and also manage the contact information.

4.3 Scope of Future Work

In the future, we have planned to add more features for Linux Toolbox. For example, users can manage background applications such as kill or end process for Linux/GNU operating system. It would be handy for all Linux users. We have a plan to increase the limit of features. And we will upgrade it with many more facilities in the future.

Mini Project Contact Management System | Based on C Language

 TABLE OF CONTENTS

1. Introduction

2. Background

3. Requirements & Design

4. Implementation

5. Result and Evaluation

6. Conclusion

7. References

8. Source Code

1. Introduction

Contact Management System is a simple console application that is developed in C Language. This program enables to store data and manage contact information. Those are essentially databases that track all (i.e. Name, Phone Number and Email address) information and communication based on user contacts.

2. Background

Features for this application: Login, Show Contact List, Insert/Add Contact, Delete Contact, Search Contact, Security Settings, Change Username and Password, Sort Contact, Log Out, Login Again or Exit program. For this project, all of the contents based on C Language.

3. Requirements & Design

Contact Management System is console base project without graphics. It is similar to the contact manager in cell phones. This mini project use file handling and data structures. For design this project I used array, function, if...else, for loop, nested loop, switch, case, and etc. Basically, this is an easy and fundamental level mini project for learning purposes. We used simple design for this project.

4. Implementation

Describe the program code in below for understanding this project-

4.1 Set Username and Password

If user run this project for first time, Set Username and Password is mandatory option to manage contact. After set Username and Password, this is not required for next time.

Sample output:

4.2 Login to manage contacts

After set Username and Password, Login to manage contacts is another mandatory option to manage contacts.

Sample output:

4.3.1 See Contact List

See Contact List can help to show all contact.

Sample output:

4.4.2 Add Contact

Add Contact can add Name, Phone Number and Email Address in Contact list.

Sample output:

4.5.3 Delete Contact

Delete Contact can delete Name, Phone Number and Email Address in Contact list on specific position. 

Sample output:

4.5.4 Search Contact

Search Contact can search by Name or Phone Number in Contact list for easily find people. 

Sample Output:

4.5.5 Sort Contact

Sort Contact can sort by Name or Phone Number on Contact list.

Sample Output:

4.5.6 Security Setting

For this project, the user can change Username and Password by Security Setting.

Sample Output:

4.5.8 Log Out

The user can log out from all features by Log Out option.

Sample Output:

5. Result and Evaluation

After run this project, we can see many features and add Name, Phone Number and Email address as Contact Management System. Here, the data will be stored in the ContactList.txt file. If the file is deleted, the user must lost his/her all data.

6. Conclusion

The principle behind constructing a Contact Management System is to effectively retrieve and implement any information. All the information related to a particular people can be linked and archived only to be retrieved later when they are required most.

7. References

This project based on Data Structure.

Source Code
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>

int size = 0, i = 0, j, position, option, isFound = 0, m, n;
FILE *fp;
char search[20];

struct contact
{
    char name[20], phone[20], email[30], username[20], password[20];

} list[100], temp;

int fileOpenRead();
int fileOpenWrite();
int readFile();
int mainMenu();
int main();
int forgetUserPass();

int optionMenu()
{
    printf("\n\n1. Main Menu\n\nEnter a following option: ");
    scanf("%d", &option);

    system("cls");

    switch(option)
    {
    case 1:
        mainMenu();
        break;

    default:
        printf("Invalid Input for Main Menu!\n\n");
        mainMenu();
        break;
    }
}

int aboutAuthor()
{
    printf("Rakibul Islam\n\n");

    optionMenu();
    system("cls");
}

int contactList()
{
    printf("Contact List");
    printf("\n------------\n\n");

    fileOpenRead();

    for(j = 0; j < size; j++)
    {
        printf("Name: %s\nPhone: %s\nEmail: %s\n\n", list[j].name, list[j].phone, list[j].email);
    }
    fclose(fp);

    optionMenu();
}

int optionMenuTwo()
{
    printf("\n\n1. Contact List\n2. Main Menu\n\nEnter a following option: ");
    scanf("%d", &option);

    system("cls");

    switch(option)
    {
    case 1:
        contactList();
        break;

    case 2:
        mainMenu();

    default:
        printf("Invalid Input for Main Menu!\n\n");
        mainMenu();
        break;
    }
}

int addContact()
{
    readFile();

    printf("Add New Contact");
    printf("\n---------------\n\n");

    fp = fopen("ContactList.txt", "wb");

    printf("Enter Name: ");
    scanf("%s", list[i].name);

    printf("Enter Phone Number: ");
    scanf("%s", list[i].phone);

    printf("Enter Email: ");
    scanf("%s", list[i].email);

    size++;
    i++;

    fileOpenWrite();
    readFile();
    printf("\n\n1. Contact List\n2. Add New Contact\n3. Main Menu\n\nEnter a following option: ");
    scanf("%d", &option);
    printf("\n");

    system("cls");

    switch(option)
    {
    case 1:
        contactList();
        break;

    case 2:
        addContact();
        break;

    case 3:
        mainMenu();
        break;

    default:
        printf("Invalid Input for Main Menu!\n\n");
        mainMenu();
        break;
    }
}

int deleteContact()
{
    printf("Delete Contact");
    printf("\n--------------\n\n");

    readFile();
    fileOpenRead();

    for(j = 0; j < size; j++)
    {
        printf("%d. Name: %s\nPhone: %s\nEmail: %s\n\n", j + 1, list[j].name, list[j].phone, list[j].email);
    }
    fclose(fp);

    printf("Enter a position to delete: ");
    scanf("%d", &position);

    if(position <= j && position > 0)
    {
        fileOpenRead();

        fp = fopen("ContactList.txt", "wb");

        for(j = position; j < size; j++)
        {
            strcpy(list[j - 1].name, list[j].name);
            strcpy(list[j - 1].phone, list[j].phone);
            strcpy(list[j - 1].email, list[j].email);
        }
        size--;
        i--;
        j--;

        fileOpenWrite();
        readFile();

        system("cls");

        printf("Deleted!");
        optionMenuTwo();
    }
    else
    {
        system("cls");

        printf("Invalid Position!");
        optionMenu();
    }
}

int searchContact()
{
    printf("Search Contact");
    printf("\n--------------\n\n");

    fileOpenRead();

    printf("Enter Name or Number: ");
    scanf("%s", search);
    printf("\n");

    for(j = 0; j < size; j++)
    {
        if((strcmp(search, list[j].name) == 0))
        {
            printf("Name: %s\nPhone: %s\nEmail: %s\n\n", list[j].name, list[j].phone, list[j].email);
            isFound = 1;
        }
        else if((strcmp(search, list[j].phone) == 0))
        {
            printf("Name: %s\nPhone: %s\nEmail: %s\n\n", list[j].name, list[j].phone, list[j].email);
            isFound = 1;
        }
    }
    fclose(fp);

    if(isFound == 1);
    else
    {
        printf("Not Found!\n\n");
    }
    optionMenu();
}

int SortByName()
{
    fileOpenRead();

    fp = fopen("ContactList.txt", "wb");

    for(m = 0; m < size - 1; m++)
    {
        for(n = 0; n < size - m - 1; n++)
        {
            if(strcmp(list[n].name, list[n + 1].name) > 0)
            {
                temp = list[n];
                list[n] = list[n + 1];
                list[n + 1] = temp;
            }
        }
    }
    fileOpenWrite();
    readFile();
    printf("Sorted!");
    optionMenuTwo();
}

int SortByNumber()
{

    fileOpenRead();
    fp = fopen("ContactList.txt", "wb");

    for(m = 0; m < size - 1; m++)
    {
        for(n = 0; n < size - m - 1; n++)
        {
            if(strcmp(list[n].phone, list[n + 1].phone) > 0)
            {
                temp = list[n];
                list[n] = list[n + 1];
                list[n + 1] = temp;
            }
        }
    }
    fileOpenWrite();
    readFile();
    printf("Sorted!");
    optionMenuTwo();
}

int SortContact()
{
    printf("Sort Contact");
    printf("\n--------------\n\n");

    readFile();

    printf("1. Sort by Name\n2. Sort by Number\n3. Main Menu\n\nEnter a following option: ");
    scanf("%d", &option);

    system("cls");

    switch(option)
    {
    case 1:
        SortByName();
        break;

    case 2:
        SortByNumber();
        break;

    case 3:
        mainMenu();
        break;

    default:
        printf("Invalid Input for Main Menu!\n\n");
        mainMenu();
        break;
    }
}

int changeUsername()
{
    readFile();

    printf("Change Username");
    printf("\n------------\n\n");

    fileOpenRead();
    fp = fopen("ContactList.txt", "wb");

    printf("New Username: ");
    scanf("%s", list[1].username);

    printf("Password: ");
    scanf("%s", list[1].password);

    if(strcmp(list[1].password, list[0].password) == 0)
    {
        system("cls");

        strcpy(list[0].username, list[1].username);

        printf("Username changed successfully!");
        printf("\n\n");

        fileOpenWrite();
        fclose(fp);
        readFile();
        optionMenu();
    }
    else
    {
        fclose(fp);
        system("cls");

        printf("Wrong password!\n\n");
        forgetUserPass();
    }
}

int changePassword()
{
    readFile();

    printf("Change Password");
    printf("\n---------------\n\n");

    fileOpenRead();

    printf("Password: ");
    scanf("%s", list[1].password);

    if(strcmp(list[1].password, list[0].password) == 0)
    {

        printf("New Password: ");
        scanf("%s", list[2].password);

confirmNewPass:

        fp = fopen("ContactList.txt", "wb");

        printf("Confirm New Password: ");
        scanf("%s", list[3].password);

        if(strcmp(list[2].password, list[3].password) == 0)
        {
            strcpy(list[0].password, list[3].password);

            fileOpenWrite();
            fclose(fp);
            system("cls");

            printf("Password changed successfully!");
            printf("\n\n");

            readFile();
            optionMenu();
        }
        else
        {
            system("cls");

            printf("New Password and Confirm New Password are not same!");
            printf("\n\n");

            //printf("Password: %s\nNew Password: %s\n", list[1].password, list[2].password);
            printf("New Password: %s\n", list[2].password);
            goto confirmNewPass;
        }
    }
    else
    {
        fclose(fp);
        readFile();
        system("cls");

        printf("Wrong password!\n\n");
        forgetUserPass();
    }
}

int securitySetting()
{
    printf("Security Setting");
    printf("\n-------------------\n\n");

    printf("\n\n1. Change Username\n2. Change Password\n3. Main Menu\n\nEnter a following option: ");
    scanf("%d", &option);

    system("cls");

    switch(option)
    {
    case 1:
        changeUsername();
        break;

    case 2:
        changePassword();
        break;

    case 3:
        mainMenu();
        break;

    default:
        printf("Invalid Input for Main Menu!\n\n");
        mainMenu();
        break;
    }

    readFile();


}

int LoggedOutPage()
{
    printf("Logged Out!\n\n");
loginOption:
    printf("1. Login\n2. Exit\n\nEnter a following option: ");
    scanf("%d", &option);

    system("cls");

    switch(option)
    {
    case 1:
        main();
        break;

    case 2:
        printf("Exiting...\n\n");
        exit(0);
        break;

    default:
        printf("Invalid Input!\n\n");
        goto loginOption;
        break;
    }
}

int forgetUserPass()
{
    printf("Forget Username or Passwowrd");
    printf("\n---------------------------\n\n");

    printf("\n\n1. Show Username\n2. Show Password\n3. Main Menu\n\n\nEnter a following option: ");
    scanf("%d", &option);

    system("cls");

    switch(option)
    {
    case 1:
        printf("Username: %s", list[0].username);
        optionMenu();
        break;

    case 2:
        printf("Password: %s", list[0].password);
        optionMenu();
        break;

    case 3:
        mainMenu();
        break;

    default:
        system("cls");

        printf("Invalid Input!\n\n");
        mainMenu();
        break;
    }
}

int mainMenu()
{
    printf("Contact Managmenet System");
    printf("\n-------------------------\n\n\n");
    printf("1. See Contact List\n\n");
    printf("2. Add Contact\n\n");
    printf("3. Delete Contact\n\n");
    printf("4. Search Contact\n\n");
    printf("5. Sort Contact\n\n");
    printf("6. Security Setting\n\n");
    printf("7. About Author\n\n");
    printf("8. Log Out\n\n");

    printf("Enter a following option: ");
    scanf("%d", &option);
    printf("\n");

    system("cls");
    switch(option)
    {
    case 1:
        contactList();
        break;

    case 2:
        addContact();
        break;

    case 3:
        deleteContact();
        break;

    case 4:
        searchContact();
        break;

    case 5:
        SortContact();
        break;

    case 6:
        securitySetting();
        break;

    case 7:
        aboutAuthor();
        break;

    case 8:
        LoggedOutPage();
        break;

    default:
        printf("Invalid Input! Please Enter 1 to 6:\n\n");
        break;
    }
}


int main()
{
    SetConsoleTitle("Contact Managment System");

    //Default Password and Username.
    //strcpy(list[0].username, "0");
    //strcpy(list[0].password, "0");

    readFile();
    fileOpenRead();

    if(strcmp(list[0].username, "") == 0 && strcmp(list[0].password, "") == 0)
    {
        fp = fopen("ContactList.txt", "wb");

        printf("\t\t\t\tSet Username and Password\n");
        printf("\t\t\t\t------------------------\n");

        printf("\t\t\t\tEnter username: ");
        scanf("%s", list[0].username);

        printf("\n\t\t\t\tEnter password: ");
        scanf("%s", list[0].password);
        printf("\n");

        fileOpenWrite();
        readFile();
        fclose(fp);

        system("cls");
    }
    fclose(fp);
login:
    readFile();
    fileOpenRead();

    printf("\t\t\t\tLogin to manage contacts\n");
    printf("\t\t\t\t------------------------\n");
    printf("\t\t\t\tEnter username: ");
    scanf("%s", list[1].username);

    printf("\n");
    printf("\t\t\t\tEnter password: ");
    scanf("%s", list[1].password);
    printf("\n");

    if(strcmp(list[1].username, list[0].username) == 0 && strcmp(list[1].password, list[0].password) == 0)
    {
        fclose(fp);

        system("cls");
        printf("\t\t\t\tLogin successful!\n\n");
        printf("\n\n");
        readFile();

        while(1) //1 for infinite loop.
        {
            mainMenu();
        }
    }
    else
    {
invalid:

        system("cls");

        printf("Wrong useraname or password!\n\n");

        printf("1. Forget Useraname or Password\n2. Login\n\nEnter a following option: ");
        scanf("%d", &option);

        system("cls");

        switch(option)
        {
        case 1:
            printf("After few second it's automatically go Login page.\n\n");
            printf("Username: %s\nPassword: %s\n\nPlease wait...", list[0].username, list[0].password);

            Sleep(5000);
            system("cls");

            goto login;
            break;

        case 2:
            goto login;
            break;

        default:
            printf("Invalid Input!\n\n");
            goto invalid;
            break;
        }
    }

}

int fileOpenRead()
{
    fp = fopen("ContactList.txt", "rb");

    fread(&list, sizeof(list), 1, fp);
    fread(&size, sizeof(size), 1, fp);
    fread(&i, sizeof(i), 1, fp);
}

int fileOpenWrite()
{
    fwrite(&list, sizeof(list), 1, fp);
    fwrite(&size, sizeof(size), 1, fp);
    fwrite(&i, sizeof(i), 1, fp);
    fclose(fp);
}

int readFile()
{
    fileOpenRead();

    for(j = 0; j < size; j++)
    {
        list[j].name;
        list[j].phone;
        list[j].email;
    }
    fclose(fp);
}

Java Programming - Projects

Coming Soon...

        1. Quiz Management System | Based on Java

        2. Contact Management System | Based on Java

        3. Student Management System | Based on Java

        4. Various Type of Pattern | Based on Java

        5. Basic Calculator | Based on Java

C Programming Projects

 1. Name Shape

 2. Mini Project Contact Management System

Coming Soon...

 3. Student Management System | Based on C Language

 4. Various Type of Pattern | Based on C Language

 5. Basic Calculator | Based on C Language

Project - Name Shape | Based on C Language

Welcome to NameShape!


ANY WORD CHALLENGE

ARHA
Project Name: Name Shape
Developer: Rakibul Islam
Release date: May 06, 2020
Available: Microsoft Windows

About: "Name Shape" which is my another project based on C Language. Putting any name or word in the input will scan every letter rapidly and create a shape of that name or word. You can use all alphabetic letters or ASCII code to create shapes. For example, if you enter CODING in input, it will CODING's shape. But if you enter ONLINE CLASS (ONLINE "Double space" CLASS) it will show BIDAY PITIBI's shape. 🥴

Restriction: Only uppercase letters will be generated in shape.


More Image

ARHA

NAME SHAPE

WORD SHAPE

CODING

PROGRAM

THANK YOU

Take A Wonderful Experience!

Download NameShape.exe


Do you want see all hidden codes? Please contact with me.

Source Code
#define WINVER 0x0500
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>

int m, n, i, j, r = 2, r2 = 0, c = 2, len, option, size = 12;
char ch1, ch2;

COORD coord = {2,2};

void setColRow(int col, int row)
{ more 3 hidden lines...
}

void bigScreen()
{ more 2 hidden lines...
}

void hidecursor()
{ more 5 hidden lines...
}

struct nameShape
{ more 2 hidden lines...
}

struct nameShape name;

int reVariable()
{ more 20 hidden lines...
}

int shapeA()
{ more 19 hidden lines...
}

int shapeB()
{ more 17 hidden lines...
}

int shapeC()
{ more 18 hidden lines...
}

int shapeD()
{ more 19 hidden lines...
}

int shapeE()
{ more 19 hidden lines...
}

int shapeF()
{ more 19 hidden lines...
}

int shapeG()
{ more 19 hidden lines...
}

int shapeH()
{ more 17 hidden lines...
}

int shapeI()
{ more 18 hidden lines...
}

int shapeJ()
{ more 19 hidden lines...
}

int shapeK()
{ more 20 hidden lines...
}

int shapeL()
{ more 19 hidden lines...
}

int shapeM()
{ more 19 hidden lines...
}

int shapeN()
{ more 20 hidden lines...
}

int shapeO()
{ more 19 hidden lines...
}

int shapeP()
{ more 17 hidden lines...
}

int shapeQ()
{ more 18 hidden lines...
}

int shapeR()
{ more 17 hidden lines...
}

int shapeS()
{ more 18 hidden lines...
}

int shapeT()
{ more 17 hidden lines...
}

int shapeU()
{ more 17 hidden lines...
}

int shapeV()
{ more 17 hidden lines...
}

int shapeW()
{ more 20 hidden lines...
}

int shapeX()
{ more 18 hidden lines...
}

int shapeY()
{ more 18 hidden lines...
}

int shapeZ()
{ more 19 hidden lines...
}

int charShape()
{ more 13 hidden lines...
}

void aboutAuthor()
{ more 47 hidden lines...
}

int main()
{ more 339 hidden lines...
}

Youtube Tutorial


Change Theme
X