Skip to content

Commit 8f345fe

Browse files
authored
Add files via upload
1) Insert N employee information into the Linked List. 2) Search an Employee and display his details. 3) Average salary of all the Employees with designation Manager.
1 parent 5971e9a commit 8f345fe

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

empll.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/* Write a program to insert N employee information into the Linked List.
2+
a. Write a function to Search an Employee and display his details.
3+
b. Display the Average salary of all the Employees with designation Manager. */
4+
5+
#include<stdio.h>
6+
#include<string.h>
7+
#include<stdlib.h>
8+
#define SIZE 10
9+
struct Employee{
10+
char name[10];
11+
char des[10];
12+
double salary;
13+
struct Employee *link;
14+
};
15+
16+
char name[SIZE];
17+
char des[SIZE];
18+
double salary;
19+
20+
21+
struct Employee* insert(struct Employee *head);
22+
void display(struct Employee *head);
23+
void displayMan(struct Employee *head);
24+
void search(struct Employee *head);
25+
26+
//typedef struct Employee Emp;
27+
28+
void main(){
29+
struct Employee *head;
30+
head=NULL;
31+
int i;
32+
33+
while(1){
34+
35+
printf("select option\n1)INSERT\n2)DISPLAY avg salary of MANAGER\n3)SEARCH\n4)DISPLAY\n");
36+
scanf("%d",&i);
37+
38+
switch(i){
39+
case 1:
40+
head=insert(head);
41+
break;
42+
case 2:
43+
displayMan(head);
44+
break;
45+
case 3:
46+
search(head);
47+
break;
48+
case 4:
49+
display(head);
50+
break;
51+
default:
52+
exit(0);
53+
}
54+
}
55+
}
56+
57+
struct Employee* insert(struct Employee *head)
58+
{
59+
struct Employee *newNode;
60+
newNode=(struct Employee*)malloc(sizeof(struct Employee));
61+
62+
printf("enter name of Employee\n");
63+
scanf("%s",name);
64+
printf("enter desgination of Employee(for MANAGER put mng)\n");
65+
scanf("%s",des);
66+
printf("enter salary of Employee\n");
67+
scanf("%d",&salary);
68+
69+
strcpy(newNode->name,name);
70+
strcpy(newNode->des,des);
71+
newNode->salary=salary;
72+
if(head!=NULL){
73+
newNode->link=head;
74+
}
75+
head=newNode;
76+
return head;
77+
}
78+
void display(struct Employee *head){
79+
if(head==NULL){
80+
printf("List is empty\n");
81+
}
82+
while(head!=NULL){
83+
printf("%s , %s , %d\n",head->name,head->des,head->salary);
84+
head=head->link;
85+
}
86+
87+
}
88+
void displayMan(struct Employee *head){
89+
if(head==NULL){
90+
printf("List is empty\n");
91+
}
92+
int i=0;
93+
char ch[]="mng";
94+
double avg=0;
95+
struct Employee *ptr;
96+
ptr=(struct Employee*)malloc(sizeof(struct Employee));
97+
ptr=head;
98+
while(ptr!=NULL){
99+
if(strcmp(ptr->des,ch)==0){
100+
avg=avg+ptr->salary;
101+
i++;
102+
}
103+
ptr=ptr->link;
104+
}
105+
avg=avg/i;
106+
printf("average salary equals = %d\n",avg);
107+
}
108+
void search(struct Employee *head){
109+
if(head==NULL){
110+
printf("List is empty\n");
111+
}
112+
else{
113+
struct Employee *ptr;
114+
ptr=(struct Employee*)malloc(sizeof(struct Employee));
115+
ptr=head;
116+
printf("enter Employee name to search\n");
117+
scanf("%s",name);
118+
while(ptr!=NULL){
119+
if(strcmp(ptr->name,name)==0){
120+
printf("Employee found...\n");
121+
printf("%s , %s , %d\n",head->name,head->des,head->salary);
122+
break;
123+
}
124+
else{
125+
printf("Employee not found\n");
126+
}
127+
ptr=ptr->link;
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)