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
|
#include <iostream>
#include <sstream>
class employee {
public:
employee() = default;
employee( std::string, double );
protected:
double hour_rate {};
private:
std::string name;
//friend:
friend std::istream& operator>>( std::istream&, employee& );
};
employee::employee( std::string name_arg, double hour_rate_arg )
: hour_rate { hour_rate_arg }
, name { name_arg }
{
}
std::istream& operator>>( std::istream& in, employee& rhs )
{
std::cout << "Enter name: ";
in >> rhs.name;
std::cout << "Enter hourly rate: ";
in >> rhs.hour_rate;
return in;
}
class partTimeEmp : public employee {
public:
partTimeEmp() = default;
partTimeEmp( std::string, double, double );
private:
double work_hours {};
//friend:
friend std::istream& operator>>( std::istream&, partTimeEmp& );
};
partTimeEmp::partTimeEmp( std::string name_arg,
double hour_rate_arg,
double work_hours_arg )
: employee( name_arg, hour_rate_arg )
, work_hours { work_hours_arg }
{
}
std::istream& operator>>( std::istream& in, partTimeEmp& rhs )
{
in >> static_cast<employee &>( rhs );
std::cout << "Enter work hours: ";
in >> rhs.work_hours;
return in;
}
int main()
{
std::istringstream iss { "Ann 13 66.6" };
partTimeEmp pte;
iss >> pte;
}
|