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