FY_BCA_C_SLIP 25_2



Slip no : 25_2 write a menu driven prog to accept and display employee (using struture)
-  search by id
-  Display name of emp having salary is greater then 10000 */


#include<conio.h>
#include<stdio.h> struct Employee

{
int eid;
char name[20]; int sal;

}e[20];
void accept(struct Employee emp[],int n)
{           int i;
for(i=0;i<n;i++)
{
printf("\n Enter employee ID : ");
scanf("%d",&emp[i].eid);
printf("\n Enter employee name : ");
scanf("%s",emp[i].name);
printf("\n Enter employee salary : "); scanf("%d",&emp[i].sal);
}
}

void display(struct Employee emp[],int n)
{
int i; printf("\nid\tname \n"); for(i=0;i<n;i++)
{ if(emp[i].sal>=10000)
{
printf("\n%d\t%s",emp[i].eid,emp[i].name);
}
}
}
void display_all(struct Employee emp[],int n)
{
int i; printf("\nid\tName\tsalary\n"); for(i=0;i<n;i++)

{              printf("\n%d\t%s\t%d",emp[i].eid,emp[i].name,emp[i].sal);
}
}


void search(struct Employee emp[],int n,int id)
{
int i,flag=0;;

for(i=0;i<n;i++)
{ if(emp[i].eid==id)
{
flag=1;
}
}
if(flag==1)
printf("\n Employee is found ");
else
printf("\n Employee is NOT found ");

}

int main()
{
int n,ch,id; clrscr(); do

{
printf("\n 1.Add Employee \n 2.Search by Empid \n 3.Employee having salary
<10000 \n 4.Display All Employee \n 0.Exit "); printf("enter your choice : "); scanf("%d",&ch);

switch(ch)
{
case 1:
printf("\n Enter how many Employee "); scanf("%d",&n);
accept(e,n);
break;

case 2:
printf("\n Enter emp id : "); scanf("%d",&id); search(e,n,id);
break;

case 3:
display(e,n);
break;

case 4 : display_all(e,n); break;

case 0: break;

default: printf("\n Inavlid choice ");
}
}while(ch!=0);
getch();

}

No comments:

Post a Comment