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
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
class Payroll
{
protected:
string name, adress;
double hoursOfWork, payRates;
public:
Payroll() : hoursOfWork(0), payRates(0)
{}
Payroll(string name, string adress, double hoursOfWork, double payRates)
{
this->name = name;
this->adress = adress;
this->hoursOfWork = hoursOfWork;
this->payRates = payRates;
}
string getName()
{return name;}
string getAdress()
{return adress;}
double getpayRates()
{return payRates;}
double getHoursOfWork()
{return hoursOfWork;}
virtual void printData(vector <Payroll>& new_V)
{cout << "Printing Payroll";}
};
class Data : public Payroll
{
public:
void fillData(vector <Payroll>& newV)
{
string name, address;
double HOW, payRates;
unsigned int size;
cout << "Enter the number of employees you want to add: "; cin >> size;
cout << endl;
for (unsigned int i = 0; i < size; i++)
{
cout << "Enter Name: "; cin.ignore(); getline(cin, name); // getline to include whitspaces
cout << "Enter address: "; cin.ignore(); getline(cin, address);
cout << "Enter hours of work: "; cin.ignore(); cin >> HOW;
cout << "Enter payrate: "; cin.ignore(); cin >> payRates;
cout << endl;
cin.ignore();
cin.clear();
Payroll emp(name, address, HOW, payRates);
newV.push_back(emp);
}
}
void printData(vector <Payroll>& new_V)
{
for (unsigned int i = 0; i < new_V.size(); i++)
{
cout << "Name: " << new_V[i].getName() << endl;
cout << "Adress: " << new_V[i].getAdress() << endl;
cout << "Hours of work: " << new_V[i].getHoursOfWork() << endl;
cout << "Payrate: " << new_V[i].getpayRates() << endl;
cout << endl;
}
}
};
int main()
{
vector <Payroll> v1;
Data obj;
obj.fillData(v1);
obj.printData(v1);
return 0;
}
| |