-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog2.cpp
More file actions
68 lines (51 loc) · 1.51 KB
/
prog2.cpp
File metadata and controls
68 lines (51 loc) · 1.51 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
/* Write a C++ Program to read the data of n employees and compute the net
* salary of each employee and compute the net salary of each employee (DA = 52%
* of Basic, income tax = 30% of the gross salary). Gross Salary = Basic + DA.
* Net salary = Gross Salary - income tax. Use the concept of array of objects.
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Employee {
private:
int emp_no;
string emp_name;
float basic, da, it, net, gross;
public:
void read_data() {
cout << "Enter employee number, employee name and basic salary: " << endl;
cin >> emp_no >> emp_name >> basic;
cal_da();
cal_gross();
cal_it();
cal_net();
}
void write_data() {
cout << "Displaying data for " << emp_no << endl;
cout << "\tEmployee Name: " << emp_name << endl;
cout << "\tBasic Salary: " << basic << endl;
cout << "\tDA: " << da << endl;
cout << "\tGross salary: " << gross << endl;
cout << "\tIncome Tax: " << it << endl;
cout << "\tNet salary: " << net << endl;
}
void cal_da() { this->da = 0.52 * basic; }
void cal_gross() { this->gross = basic + da; }
void cal_it() { this->it = 0.3 * gross; }
void cal_net() { this->net = gross - it; }
};
int main() {
int n;
cout << "Enter the no. of employees: ";
cin >> n;
vector<Employee> e(n);
for (int i = 0; i < n; i++) {
cout << "Employee: " << i + 1 << "details: " << endl;
e[i].read_data();
}
for (int i = 0; i < n; i++) {
e[i].write_data();
}
return 0;
}