1.

Define a structure for an employee of an organization having employee code, name, address, phone number and number of dependents. Assume that “allEmployees” is an array of employees in ascending order on the employee code. Write a function to display the details of an employee given its employee code. 

Answer»

A structure for an employee and a function to display the details of an employee:

struct employee

{

int emp_code;

char emp_name[30];

char emp_address[50];

char emp_ph_num[10]; int no_of_dep;

allEmployees[100],b;

void display()

{

int ctr=0;

fp=fopen("employee.c","r");

rewind(fp)

while(fread(&allEmployees,sizeof(allEmployees[i]),1

fp)==1)

{

ctr++;

clrscr();

heading();

printf("\n\n\n\

Following are the details :-");

printf("\n\n\tRecord #%d",ctr);

printf("\n\n\t\tCode : %d",allEmployees[i].emp_code)

printf("\n\n\t\tName : %s",allEmployees[i].emp_name)

printf("\n\n\t\tAddress : %s",allEmployees[i].emp_address)

printf("\n\n\t\tPhoneNumber:%s"allEmployees[i].emp_ph_num

printf("\n\n\t\tNumber.Dependents

%s",allEmployees[i].no_of_dep);

printf("\n\n\n\n\t\tPlease Press Enter...");

getch();

}

}  



Discussion

No Comment Found

Related InterviewSolutions