-
Notifications
You must be signed in to change notification settings - Fork 23
/
4.cpp
54 lines (44 loc) · 1.24 KB
/
4.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
/*
Create an employee class, basing it on Exercise 4 of Chapter 4. The member data should
comprise an int for storing the employee number and a float for storing the employee’s
compensation. Member functions should allow the user to enter this data and display it.
Write a main() that allows the user to enter data for three employees and display it.
*/
// author @Nishant
#include<iostream>
using namespace std;
class employee {
private:
int emp_num;
float emp_comp;
public:
employee(): emp_num(0), emp_comp(0) { }
employee(int empNum, float empCom): emp_num(empNum), emp_comp(empCom){ }
void setData();
void display() const;
};
void employee::setData() {
cout << "\nEnter employee Number: ";
cin >> emp_num;
cout << "Enter employee Compensation: ";
cin >> emp_comp;
cout << endl;
}
void employee::display() const {
cout << "Employee Number: " << emp_num << endl;
cout << "Employee Compensation: $" << emp_comp <<endl;
}
int main() {
employee emp1, emp2;
employee emp3(12, 34.6);
emp1.setData();
emp2.setData();
cout << "\nDetails of first employee: \n";
emp1.display();
cout << "\nDetails of second employee: \n";
emp2.display();
cout <<"\nDetails of third employee: \n";
emp3.display();
cout <<endl;
return 0;
}