-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee.cpp
109 lines (102 loc) · 2.39 KB
/
Employee.cpp
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
#include <iostream>
#include <string.h>
using namespace std;
int obj;
class Employee
{
public:
int id, n;
char name[100];
float salary;
public:
void accept();
int findEmploy(char *);
void display();
Employee()
{
cout << "Constructor " << ++obj << " Invoked" << endl;
}
~Employee()
{
cout << "Destructor " << obj-- << " Invoked" << endl;
}
};
void Employee ::accept()
{
cout << "Name of Employee : ";
cin >> name;
cout << "ID : ";
cin >> id;
cout << "Salary : Rs. ";
cin >> salary;
cout << "---------------------------------------------";
}
int Employee ::findEmploy(char *nm)
{
// b=strcmpi(s1,s2); -1 => s2 is before s1, 1 => s1 before s2, 0 => s1 equals s2
if (strcmp(nm, name) == 0)
{
return 1;
}
else
return 0;
}
void Employee ::display()
{
cout << "\nEmployee Name : " << name;
cout << "\nID : " << id;
cout << "\nSalary : Rs. " << salary << endl;
}
int main(void)
{
int n;
cout << "\nEnter number of employees : ";
cin >> n;
Employee e[n]; // creating an object of Employee
for (int i = 0; i < n; i++)
{
cout << "\nEnter details of employee " << i+1 << " : \n";
e[i].accept();
}
cout << "\n\n>>>>>>>>>>>>>>>> LIST OF ALL EMPLOYEES WITH DETAILS <<<<<<<<<<<<<<<< \n";
for (int i = 0; i < n; i++)
{
e[i].display();
cout << "\n********************************************************************";
}
int flag = 0;
char nam[100];
cout << "\nEnter employee name you want to search : ";
cin >> nam;
int i = 0, j = 0;
for (i = 0; i < n; i++)
{
j = e[i].findEmploy(nam);
if (j == 1)
{
flag = 1;
break;
}
}
if (flag == 1)
{
cout << "Employee name found!\n";
e[i].display();
}
else
{
cout << "\nEmployee name Not found." << endl;
}
cout << "\n********************************************************************";
// code to find highest salary :
float max = e[0].salary;
for (int i = 1; i < n; i++)
{
if (max < e[i].salary)
{
max = e[i].salary;
}
}
cout << "\nHighest salary is : Rs. " << max << "\n\n";
return 0;
}