Join Whatsapp Channel for Ignou latest updates JOIN NOW

Using Structures write an interactive program in C language to create an application program for a small office to maintain the employee’s database. This application should be having menu options like Creating a New Record Reading/Listing of Records Modify the record Delete the record Each employee record should have Employee Name, Employee ID, Department Name, Salary, Position, Date of Joining, etc. The application should be designed user-friendly. Note: You must execute the program and submit the program logic, sample input and output along with the necessary documentation for this question. Assumptions can be made wherever necessary

Sure, here’s an example program in C that fulfills your requirements:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_EMPLOYEES 100

struct Employee {
    char name[50];
    int id;
    char department[50];
    float salary;
    char position[50];
    char date_of_joining[20];
};

struct Employee employees[MAX_EMPLOYEES];
int employeeCount = 0;

void createRecord() {
    if (employeeCount >= MAX_EMPLOYEES) {
        printf("Database is full. Cannot add more records.\n");
        return;
    }

    struct Employee newEmployee;

    printf("Enter employee name: ");
    scanf("%s", newEmployee.name);
    printf("Enter employee ID: ");
    scanf("%d", &newEmployee.id);
    printf("Enter department name: ");
    scanf("%s", newEmployee.department);
    printf("Enter salary: ");
    scanf("%f", &newEmployee.salary);
    printf("Enter position: ");
    scanf("%s", newEmployee.position);
    printf("Enter date of joining (YYYY-MM-DD): ");
    scanf("%s", newEmployee.date_of_joining);

    employees[employeeCount++] = newEmployee;
    printf("Record created successfully.\n");
}

void listRecords() {
    printf("Employee Records:\n");
    printf("-----------------------------------------------------------------------------\n");
    printf("Name\t\tID\tDepartment\tSalary\tPosition\tDate of Joining\n");
    printf("-----------------------------------------------------------------------------\n");
    for (int i = 0; i < employeeCount; i++) {
        printf("%s\t\t%d\t%s\t\t%.2f\t%s\t\t%s\n",
               employees[i].name,
               employees[i].id,
               employees[i].department,
               employees[i].salary,
               employees[i].position,
               employees[i].date_of_joining);
    }
    printf("-----------------------------------------------------------------------------\n");
}

void modifyRecord() {
    int id;
    printf("Enter employee ID to modify: ");
    scanf("%d", &id);

    for (int i = 0; i < employeeCount; i++) {
        if (employees[i].id == id) {
            printf("Enter new employee name: ");
            scanf("%s", employees[i].name);
            printf("Enter new department name: ");
            scanf("%s", employees[i].department);
            printf("Enter new salary: ");
            scanf("%f", &employees[i].salary);
            printf("Enter new position: ");
            scanf("%s", employees[i].position);
            printf("Enter new date of joining (YYYY-MM-DD): ");
            scanf("%s", employees[i].date_of_joining);
            printf("Record modified successfully.\n");
            return;
        }
    }
    printf("Employee with ID %d not found.\n", id);
}

void deleteRecord() {
    int id;
    printf("Enter employee ID to delete: ");
    scanf("%d", &id);

    for (int i = 0; i < employeeCount; i++) {
        if (employees[i].id == id) {
            for (int j = i; j < employeeCount - 1; j++) {
                employees[j] = employees[j + 1];
            }
            employeeCount--;
            printf("Record deleted successfully.\n");
            return;
        }
    }
    printf("Employee with ID %d not found.\n", id);
}

int main() {
    int choice;

    do {
        printf("\nEmployee Database Management System\n");
        printf("1. Create New Record\n");
        printf("2. List Records\n");
        printf("3. Modify Record\n");
        printf("4. Delete Record\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                createRecord();
                break;
            case 2:
                listRecords();
                break;
            case 3:
                modifyRecord();
                break;
            case 4:
                deleteRecord();
                break;
            case 5:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice. Please try again.\n");
        }
    } while (choice != 5);

    return 0;
}

This program creates an interactive employee database management system. You can compile and execute it to see how it works. Below are the sample inputs and outputs:

Sample Input:

1
John
101
IT
50000
Manager
2023-05-20
2
3
101
Johnathan
Finance
60000
Lead
2022-12-15
2
4
101
5

Sample Output:

Employee Database Management System
1. Create New Record
2. List Records
3. Modify Record
4. Delete Record
5. Exit
Enter your choice: 1
Enter employee name: John
Enter employee ID: 101
Enter department name: IT
Enter salary: 50000
Enter position: Manager
Enter date of joining (YYYY-MM-DD): 2023-05-20
Record created successfully.

Employee Database Management System
1. Create New Record
2. List Records
3. Modify Record
4. Delete Record
5. Exit
Enter your choice: 2
Employee Records:
-----------------------------------------------------------------------------
Name            ID      Department      Salary  Position        Date of Joining
-----------------------------------------------------------------------------
John            101     IT              50000.00        Manager 2023-05-20
-----------------------------------------------------------------------------

Employee Database Management System
1. Create New Record
2. List Records
3. Modify Record
4. Delete Record
5. Exit
Enter your choice: 3
Enter employee ID to modify: 101
Enter new employee name: Johnathan
Enter new department name: Finance
Enter new salary: 60000
Enter new position: Lead
Enter new date of joining (YYYY-MM-DD): 2022-12-15
Record modified successfully.

Employee Database Management System
1. Create New Record
2. List Records
3. Modify Record
4. Delete Record
5. Exit
Enter your choice: 2
Employee Records:
-----------------------------------------------------------------------------
Name            ID      Department      Salary  Position        Date of Joining
-----------------------------------------------------------------------------
Johnathan       101     Finance         60000.00        Lead    2022-12-15
-----------------------------------------------------------------------------

Employee Database Management System
1. Create New Record
2. List Records
3. Modify Record
4. Delete Record
5. Exit
Enter your choice: 4
Enter employee ID to delete: 101
Record deleted successfully.

Employee Database Management System
1. Create New Record
2. List Records
3. Modify Record
4. Delete Record
5. Exit
Enter your choice: 5
Exiting...
error: Content is protected !!