Employee Data Entry (Nested Structures)

Algorithm

Step 1: Start

Step 2: Define structures for DOB and Employee

Step 3: Declare an array of Employee structures

Step 4: Loop to input employee ID, name, and DOB

Step 5: Loop to display entered employee information

Step 6: End

Flowchart

graph TD; A([Start]) --> B[Define structures DOB and Employee]; B --> G[Define the strucure of Employee \n and declacre the DOB strucure variable here] G --> C[Declare employee array]; C --> D[/Loop: Input ID, Name, DOB/]; D --> E[/Loop: Display all employee data/]; E --> F([End]); classDef start fill:#00cc44,stroke:#006622,stroke-width:2px,color:#ffffff; classDef stop fill:#ff4444,stroke:#cc0000,stroke-width:2px,color:#ffffff; classDef process fill:#4488ff,stroke:#0044cc,stroke-width:2px,color:#ffffff; classDef input_output fill:#ffdd44,stroke:#cc9900,stroke-width:2px,color:#000000; class A start; class F stop; class B,C,G process; class D,E input_output;
Dr.M.Raja Roy

Program

// Write a C program to collect the employee data such as eid,name,dob,salary etc. using nested structures.
#include <stdio.h>
struct dob {
    int day;
    int month;
    int year;
};
struct employee {
    int eid;
    char name[100];
    struct dob d1;
};

int main() {
    int i;
    struct employee emp[3];
    printf("Enter employee details :");
    for(i=0;i<3;i++) {
        printf("\nEnter Eid : ");
        scanf("%d",&emp[i].eid);
        printf("\nEnter Employee Name : ");
        scanf("%s",emp[i].name);
        printf("\nEnter DOB (Day-Month-Year) : ");
        scanf("%d %d %d",&emp[i].d1.day,&emp[i].d1.month,&emp[i].d1.year);
    }
    // Display data
    printf("\nEmployee data :");
    printf("\neid \tName \tDOB(Day-Month-Year)");
    for(i=0;i<3;i++) {
        printf("\n%d \t%s \t%d-%d-%d",emp[i].eid,emp[i].name,emp[i].d1.day,emp[i].d1.month,emp[i].d1.year);
    }
    return 0;
}
                

Test Case Output
Enter employee details:

Enter Eid : 101
Enter Employee Name : John
Enter DOB (Day-Month-Year) : 12 4 1990

Enter Eid : 102
Enter Employee Name : Alice
Enter DOB (Day-Month-Year) : 23 7 1985

Enter Eid : 103
Enter Employee Name : Bob
Enter DOB (Day-Month-Year) : 5 11 1992

Employee data:
eid     Name    DOB(Day-Month-Year)
101     John    12-4-1990
102     Alice   23-7-1985
103     Bob     5-11-1992