-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion7_initial_code.cpp
More file actions
138 lines (101 loc) · 3.26 KB
/
Question7_initial_code.cpp
File metadata and controls
138 lines (101 loc) · 3.26 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
131
132
133
134
135
136
137
138
//#ifndef QUES7H
//#define QUES_7
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
class Employee
{
public:
Employee()
{
//intentionally left blank
}
//Employee();
//function to calculate the amount deducted from salary for tax
double calcTax(double grossPay, double deductions, Employee employee);
//function to calculate gross pay
double calcGrossPay(Employee employee);
//function to calculate how much should be deducted from the gross salary for pension and medical aid
double calcDeductions(Employee employee);
//accessor functions
double getBasicSalary();
double getPension();
double getMedicalAid();
float getTaxPercentage();
friend istream& operator>>(istream& sendIn, Employee& employee);
private:
//private variables
double basicSalary;
double pension;
double medicalAid;
float taxPercentage;
};
#include "ques7.h"
#include <string>
#include <iostream>
using namespace std;
//default constructor
//Employee::Employee(double basicSalary, double pension, double medicalAid, float tax);
// {
// basicSalary = 0;
// pension = 0.00;
//medicalAid = 0.00;
//taxPercentage = 0.00;
//}
//accessor functions
double Employee::getBasicSalary()
{
return basicSalary;
}
double Employee::getPension()
{
return pension;
}
double Employee::getMedicalAid()
{
return medicalAid;
}
float Employee::getTaxPercentage()
{
return taxPercentage;
}
//function to calculate the amount deducted from salary for tax
double Employee::calcTax(double grossPay, double deductions, Employee employee)
{
float taxP = employee.getTaxPercentage();
double taxAmount = taxP*(grossPay-deductions);
return taxAmount;
}
//function to calculate gross pay
double Employee::calcGrossPay(Employee employee)
{
//get the values
double theBasicSalary = employee.getBasicSalary();
double thePension = employee.getPension();
double theMed= employee.getMedicalAid();
//calculate gross salary
double grossPay = theBasicSalary+thePension+theMed;
return grossPay;
}
//function to calculate how much should be deducted from the gross salary for pension and medical aid
double Employee::calcDeductions(Employee employee)
{
double thePension = employee.getPension();
double theMed= employee.getMedicalAid();
double deductions = (theMed*2) + (thePension*2);
return deductions;
}
//overloaded extraction operator that can be used to input values of type Employee into the object
istream& operator>>(istream& sendIn, Employee& employee)
{
cout << "\nEnter the basic salary: ";
sendIn >> employee.basicSalary;
cout << "\nEnter the pension amount that the employee pays: ";
sendIn >> employee.pension;
cout << "\nEnter the medical aid amount that the employee pays: ";
sendIn >> employee.medicalAid;
cout << "\nEnter the tax percentage: ";
sendIn >> employee.taxPercentage;
return sendIn;
}