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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
public:
Employee();//default constructor
Employee(string n, string st, double wp, int d);//constructor with parameters
void print() const;
void set_name(string n);
void set_status(string st);
void set_weeklyPay(double wp);
void set_dependents(int d);
string get_name() const;
string get_status() const;
double get_weeklyPay() const;
int get_dependents() const;
double taxDeduction() const;
private:
string name;//holds name
string status;//holds status
double weeklyPay;// holds weeklypay
int dependents;//holds dependents
};
Employee::Employee()
{
name = " ";
status = " ";
weeklyPay = 0;
dependents = 0;
}
Employee::Employee(string n, string st, double wp, int d,)
{
name = n;
status = st;
weeklyPay = wp;
dependents = d;
}
void Employee::set_name(string n)
{
name = n;
}
string Employee::get_name() const
{
return name;
}
void Employee::set_status(string st)
{
status = st;
}
string Employee::get_status() const
{
return status;
}
void Employee::set_weeklyPay(double wp)
{
weeklyPay = wp;
}
double Employee::get_weeklyPay() const
{
return weeklyPay;
}
void Employee::set_dependents(int d)
{
dependents = d;
}
int Employee::get_dependents() const
{
return dependents;
}
void Employee::print() const
{
cout << status << " " << dependents << endl;
}
double Employee::taxDeduction()const
{
if(status == "m")
{
if (dependents <= 2)
taxDeduction = 20;
else if (dependents == 3)
taxDeduction = 15;
else if (dependents == 4)
taxDeduction = 10;
else if (dependents >= 5)
taxDeduction = 8;
{
else
}
if (dependents <= 2)
taxDeduction = 25;
else if (dependents == 3)
taxDeduction = 20;
else if (dependents == 4)
taxDeduction = 14;
else if (dependents >= 5)
taxDeduction = 10;
}
cout << "Your tax deduction is : " << taxDeduction << flush;
}
int main() {
string status;//holds status
int dependents;//holds dependents
double weeklyPay;// holds weeklypay
string name;//holds name
vector<Employee> myList(3);
Employee e( Jim, m, 400, 2 );
myList[0] = e;
Employee e2( Mike, s, 600, 0 );
myList[0] = e2;
Employee e3( Sandra, m, 535, 1 );
myList[0] = e3;
for (int i = 0; i < myList.size(); i++)
myList[i].print();
return 0;
}
|