-
Notifications
You must be signed in to change notification settings - Fork 5
/
chap4ep1.cpp
138 lines (135 loc) · 3.1 KB
/
chap4ep1.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include<iostream>
#include<stdlib.h>
using namespace std;
class Employee{
float salary[10];
float max_salary=0.0;
float min_salary;
int salary_count=0;
int n=10;
float asc_salary[10];
int min=0,tmp;
public:
void accept_details();
void display_max();
void display_min();
void display_avg();
void count();
};
void Employee::accept_details()
{
cout<<"Enter the salary of 10 Employees:"<<endl;
for(int i=0;i<n;i++){
cin>>salary[i];
}
cout<<"All ten employees salary has been inserted"<<endl;
}
void Employee:: display_max(){
if(salary[0]==0){
cout<<"Please first enter some data(press1)"<<endl;
}
else{
for(int i=0;i<n;i++){
if(salary[i]>max_salary)
{
max_salary=salary[i];
}
}
cout<<"maximum salry of employees is :"<<max_salary<<endl;
}
}
void Employee::display_min(){
min_salary=salary[0];
if(salary[0]==0)
{
cout<<"please first enter some data(press 1)"<<endl;
}
else{
for(int i=0;i<n;i++)
{
if(salary[i]<min_salary)
{
min_salary=salary[i];
}
}
cout<<"Minimum salary of a employee is"<<min_salary<<endl;
}
}
void Employee::display_avg()
{
for(int i=0;i<n;i++){
if(salary[i]>1000){
salary_count++;
}
}
cout<<"There are"<<salary_count<<"employees whose salary is greater than 1000"<<endl;
}
void Employee::count(){
if(salary[0]==0)
{
cout<<"Please enter some data<<(press 1)"<<endl;
}
else{
for(int i=0;i<n-1;i++){
min=i;
for(int j=i+2;j<n;j++){
if(salary[j]<salary[min]){
min=j;
tmp=salary[i];
salary[i]=salary[min];
salary[min]=tmp;
}
}
}
cout<<"salary in Ascending order:"<<endl;
for(int i=0;i<n;i++){
cout<<salary[i]<<endl;
}
for(int i=0;i<n;i++){
min=i;
for(int j=i+1;j<n-1;j++){
if(salary[j]>salary[min])
{
min=j;
tmp=salary[i];
salary[i]=salary[min];
salary[min]=tmp;
}
}
}
cout<<"Salary in descending order :"<<endl;;
for(int i=0;i<n-1;i++){
cout<<salary[i]<<endl;
}
}
}
int main(){
Employee emp;
int ch=0;
cout<<"Press 1 to enter the salary of ten employees"<<endl;
cout<<"Press 2 to find the maximum salary"<<endl;
cout<<"Press 3 to find the minimum salary"<<endl;
cout<<"Press 4 to the salary greater than 1000"<<endl;
cout<<"Press 5 to arrange the salary in ascending and descending order"<<endl;
cout<<"Press 6 to exit"<<endl;
while(1){
cout<<"enter your choice(1-6)"<<endl;
cin>>ch;
switch(ch){
case 1: emp.accept_details();
break;
case 2: emp.display_max();
break;
case 3: emp.display_min();
break;
case 4: emp.display_avg();
break;
case 5: emp.count();
break;
case 6: exit(0);
break;
default:
cout<<"Invalid choice"<<endl;
}
}
}