Employee Record System

Mini project Employee record system using C

The employee record system is very simple and for very beginner mini project. It is based one the menu-driven program for elementary database management. It employ all the basic technique of file handling in C. It consists of following features
  • Writing the data in binary file
  • Reading the data from binary file
  • Modify the record
  • Delete the record
This project is a learning milestone for beginner who want to step into the database management project in C.
Source Code
/**
*  A menu-driven program for elementary database management
*  @author: Bibek Subedi
*  @language: C
*  This program uses file handling in Binary mode
*/

/// List of library functions
#include <stdio.h> ///for input output functions like printf, scanf
#include <stdlib.h>
#include <conio.h>
#include <windows.h> ///for windows related functions (not important)
#include <string.h>  ///string operations

/** List of Global Variable */
COORD coord = {0,0}; /// top-left corner of window

/**
    function : gotoxy
    @param input: x and y coordinates
    @param output: moves the cursor in specified position of console
*/
void gotoxy(int x,int y){
    coord.X = x; coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

/** Main function started */

int main(){
    FILE *fp, *ft; /// file pointers
    char another, choice;

    /** structure that represent a employee */
    struct emp{
        char name[40]; ///name of employee
        int age; /// age of employee
        float bs; /// basic salary of employee
    };

    struct emp e; /// structure variable creation

    char empname[40]; /// string to store name of the employee

    long int recsize; /// size of each record of employee

    /** open the file in binary read and write mode
    * if the file EMP.DAT already exists then it open that file in read write mode
    * if the file doesn't exit it simply create a new copy
    */
    fp = fopen("EMP.DAT","rb+");
    if(fp == NULL){
        fp = fopen("EMP.DAT","wb+");
        if(fp == NULL){
            printf("Connot open file");
            exit(1);
        }
    }

    /// sizeo of each record i.e. size of structure variable e
    recsize = sizeof(e);

    /// infinite loop continues untile the break statement encounter
    while(1){
        system("cls"); ///clear the console window
        gotoxy(30,10); /// move the cursor to postion 30, 10 from top-left corner
        printf("1. Add Record"); /// option for add record
        gotoxy(30,12);
        printf("2. List Records"); /// option for showing existing record
        gotoxy(30,14);
        printf("3. Modify Records"); /// option for editing record
        gotoxy(30,16);
        printf("4. Delete Records"); /// option for deleting record
        gotoxy(30,18);
        printf("5. Exit"); /// exit from the program
        gotoxy(30,20);
        printf("Your Choice: "); /// enter the choice 1, 2, 3, 4, 5
        fflush(stdin); /// flush the input buffer
        choice  = getche(); /// get the input from keyboard
        switch(choice){
            case '1':  /// if user press 1
                system("cls");
                fseek(fp,0,SEEK_END); /// search the file and move cursor to end of the file
                                        /// here 0 indicates moving 0 distance from the end of the file

                another = 'y';
                while(another == 'y'){ /// if user want to add another record
                    printf("\nEnter name: ");
                    scanf("%s",e.name);
                    printf("\nEnter age: ");
                    scanf("%d", &e.age);
                    printf("\nEnter basic salary: ");
                    scanf("%f", &e.bs);

                    fwrite(&e,recsize,1,fp); /// write the record in the file

                    printf("\nAdd another record(y/n) ");
                    fflush(stdin);
                    another = getche();
                }
                break;
            case '2':
                system("cls");
                rewind(fp); ///this moves file cursor to start of the file
                while(fread(&e,recsize,1,fp)==1){ /// read the file and fetch the record one record per fetch
                    printf("\n%s %d %.2f",e.name,e.age,e.bs); /// print the name, age and basic salary
                }
                getch();
                break;

            case '3':  /// if user press 3 then do editing existing record
                system("cls");
                another = 'y';
                while(another == 'y'){
                    printf("Enter the employee name to modify: ");
                    scanf("%s", empname);
                    rewind(fp);
                    while(fread(&e,recsize,1,fp)==1){ /// fetch all record from file
                        if(strcmp(e.name,empname) == 0){ ///if entered name matches with that in file
                            printf("\nEnter new name,age and bs: ");
                            scanf("%s%d%f",e.name,&e.age,&e.bs);
                            fseek(fp,-recsize,SEEK_CUR); /// move the cursor 1 step back from current position
                            fwrite(&e,recsize,1,fp); /// override the record
                            break;
                        }
                    }
                    printf("\nModify another record(y/n)");
                    fflush(stdin);
                    another = getche();
                }
                break;
            case '4':
                system("cls");
                another = 'y';
                while(another == 'y'){
                    printf("\nEnter name of employee to delete: ");
                    scanf("%s",empname);
                    ft = fopen("Temp.dat","wb");  /// create a intermediate file for temporary storage
                    rewind(fp); /// move record to starting of file
                    while(fread(&e,recsize,1,fp) == 1){ /// read all records from file
                        if(strcmp(e.name,empname) != 0){ /// if the entered record match
                            fwrite(&e,recsize,1,ft); /// move all records except the one that is to be deleted to temp file
                        }
                    }
                    fclose(fp);
                    fclose(ft);
                    remove("EMP.DAT"); /// remove the orginal file
                    rename("Temp.dat","EMP.DAT"); /// rename the temp file to original file name
                    fp = fopen("EMP.DAT", "rb+");
                    printf("Delete another record(y/n)");
                    fflush(stdin);
                    another = getche();
                }
                break;
            case '5':
                fclose(fp);  /// close the file
                exit(0); /// exit from the program
        }
    }
    return 0;
}

Output 

Chapter-5 (Social Impact on IT)


Question: What is a virus, worms and Trojan horses?

Answer:

A computer virus attaches itself to a program or file enabling it to spread from one computer to another, leaving infections as it travels. Like a human virus, a computer virus can range in severity: some may cause only mildly annoying effects while others can damage your hardware, software or files.

A worm is similar to a virus by design and is considered to be a sub-class of a virus. Worms spread from computer to computer, but unlike a virus, it has the capability to travel without any human action.

A Trojan Horse is full of as much trickery as the mythological Trojan Horse it was named after. The Trojan Horse, at first glance will appear to be useful software but will actually do damage once installed or run on your computer.

Question: What is Anti-Virus Software?

Answer: Antivirus or anti-virus software (often abbreviated as AV), sometimes known as anti-malware software, is computer software used to prevent, detect and remove malicious software. Antivirus software was originally developed to detect and remove computer viruses, hence the name.

Question: What is Spyware?



Answer: Software that enables a user to obtain covert information about another's computer activities by transmitting data covertly from their hard drive.

Question: What is Malware Virus?

Answer: Software which is specifically designed to disrupt or damage a computer system.

Question: What is Spam?

Answer: It is irrelevant or unsolicited messages sent over the Internet, typically to large numbers of users, for the purposes of advertising, phishing, spreading malware, etc.

Question: Define Data Backup and recovery tools and methods?

Answer: A backup, or the process of backing up, refers to the copying and archiving of computer data so it may be used to restore the original after a data loss event.
  • Normal (Full) Backups
  • Incremental Backups
  • Differential Backups
  • Mirror Backups

A data recovery is a process of salvaging inaccessible data from corrupted or damaged secondary storage, removable media or files, when the data they store cannot be accessed in a normal way.

Four phases of data recovery
Phase 1: Repair the hard disk drive
Phase 2: Image the drive to a new drive or a disk image file
Phase 3: Logical recovery of files, partition, MBR and MFT
Phase 4: Repair damaged files that were retrieved

Question: What is Online Backups?

Answer: Online backup, also known as remote backup, is a method of offsite data storage in which files, folders, or the entire contents of a hard drive are regularly backed up on a remote server or computer with a network connection.

Question: What is Hacker and Cracker?



Answer:

Hacker is a term used by some to mean "a clever programmer" and by others, especially those in popular media, to mean "someone who tries to break into computer systems."
A cracker is someone who breaks into someone else's computer system, often on a network; bypasses passwords or licenses in computer programs; or in other ways intentionally breaches computer security.

Question: Define Social Networking Information security Provisions in e-commerce?

Answer:  
E-commerce is defined as the buying and selling of products or services over electronic systems such as the Internet and to a lesser extent, other computer networks.

Any E-Commerce system must meet four integral requirements:

a) Privacy – information exchanged must be kept from unauthorized parties
b) Integrity – the exchanged information must not be altered or tampered with
c) Authentication – both sender and recipient must prove their identities to each other and
d) Non-repudiation – proof is required that the exchanged information was indeed received.

Question: Extract Benefits of ICT in Education?

Answer:

Information and Communication Technologies have recently gained groundswell of interest. It is a significant research area for many scholars around the globe.  Their nature has highly changed the face of education over the last few decades.

For most Asian countries, the use of ICT in education and training has become a priority during the last decade. However, very few have achieved progress. Indeed, a small percentage of schools in some countries achieved high levels of effective use of ICT to support and change the teaching and learning process in many subject areas. Others are still in the early phase of Information and Communication Technologies adoption.

In addition, schools with sufficient ICT resources achieved better results than those that are not well-equipped.  There is a significant improvement on learners’ performances.  Finally, teachers become more convinced that educational achievements of pupils are due to good ICT use. In fact, high percentage of teachers in India (86%) states that pupils are more motivated when computers and Internet are being used in class.

Question: Define Impact of ICT on Society: Knowledge based society, Infomania, Digital Unity and Digital Divide?

Answer:

The growth of Information and communication technology (ICT) has significantly increased the world’s capacity for creation of raw data and the speed at which it is produced. The advent of the internet delivered unheard of quantities of information to people.

The evolution of the internet from Web 1.0 to Web 2.0 offered individuals tools to connect with each other worldwide as well as become content users and producers. Innovation in digital technologies and mobile devices offers individuals a means to connect anywhere anytime where digital technologies are accessible. Tools of ICT have the potential to transform education, training, employment and access to life-sustaining resources for all members of society.

The emergence f IT has impacted human lives on a grand scale by influencing all spheres of human’s life and all sectors of society. The IT society has resulted into many new concepts and terms, some of which we are discussing below.

Knowledge Based Society


A knowledge based society is the one that lays maximum emphasis on knowledge. This is it, it creates, shares and uses the knowledge for the prosperity and well-being of its people. Thus the Knowledge Based Society is a society where knowledge is the primary production resources instead of labor and capital. A knowledge society generates, processes, shares and makes available to all members of the society knowledge that may be used to improve the human condition.

Infomania

Oxford dictionaries describe the Infomania as the compulsive desire to check or accumulate news and information, typically via mobile or computer. Young people are finding it increasingly harder to switch off smart phones and internet access, and are suffering as a result.
The constant urge and need to check emails or social media could classify a person as infomaniac. The infomaniacs are mostly sleep-deprived and they have compromised diets resulting, into bad physical and mental health.

Digital Unity

Digital Unity or digital inclusion is the ability of individuals to access and use information and communication technologies. The access and use of information and communication technologies impacts individuals and the community as a whole. Digital Unity ensures that all stake-holders of the society get equal and fair share of technology use in their lives.

Digital Divides

The Digital Divides refers to the difference between people who have easy access to the internet and those who do not. A lack of access is believed to be disadvantage to those on the disadvantaged side of the Digital Divide because of huge knowledge base that can only be found online.