File tree Expand file tree Collapse file tree 3 files changed +51
-7
lines changed Expand file tree Collapse file tree 3 files changed +51
-7
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,32 @@ BasicEmployee::~BasicEmployee()
10
10
{
11
11
std::cout << " ***BasicEmployee destructor***" << std::endl;
12
12
}
13
- std::string BasicEmployee::getFirstName ()
13
+ std::string BasicEmployee::getFirstName () const
14
14
{
15
15
return FirstName;
16
16
}
17
- std::string BasicEmployee::getLastName ()
17
+ std::string BasicEmployee::getLastName () const
18
18
{
19
19
return LastName;
20
20
}
21
+ std::string BasicEmployee::getFullName () const
22
+ {
23
+ return FirstName + ' ' + LastName;
24
+ }
25
+ void BasicEmployee::setPay (int pay)
26
+ {
27
+ this ->hourlyPay = pay;
28
+ }
29
+ void BasicEmployee::workHours (int hours)
30
+ {
31
+ this ->hoursWorked += hours;
32
+ }
33
+ int BasicEmployee::getPaycheck ()
34
+ {
35
+ int ret = this ->hoursWorked * this ->hourlyPay ;
36
+
37
+ this ->hoursWorked = 0 ;
38
+
39
+ return ret;
40
+
41
+ }
Original file line number Diff line number Diff line change @@ -7,8 +7,14 @@ class BasicEmployee
7
7
{
8
8
public:
9
9
BasicEmployee (std::string FirstName,std::string LastName);
10
- std::string getFirstName ();
11
- std::string getLastName ();
10
+ std::string getFirstName () const ;
11
+ std::string getLastName () const ;
12
+ std::string getFullName () const ;
13
+
14
+ void workHours (int hours);
15
+ void setPay (int pay);
16
+ int getPaycheck ();
17
+
12
18
virtual ~BasicEmployee ();
13
19
private:
14
20
std::string FirstName;
Original file line number Diff line number Diff line change 1
1
#include " BasicEmployee.hpp"
2
2
#include < iostream>
3
+ #include < tuple>
3
4
4
5
6
+ void PrintPay (BasicEmployee& emp)
7
+ {
8
+ std::cout << emp.getFullName () << " is payed " << emp.getPaycheck () << std::endl;
9
+ }
5
10
int main (void )
6
11
{
7
- BasicEmployee bob (" Bob" ," Smith" );
8
- std::cout << " Hello " << bob.getFirstName () << " " << bob.getLastName () << std::endl;
9
-
12
+ BasicEmployee emp1 (" Arthur" ," Dent" );
13
+ BasicEmployee emp2 (" Zaphod" , " Beeblebrox" );
14
+ emp1.setPay (15 );
15
+ emp2.setPay (132 );
16
+
17
+
18
+ emp1.workHours (50 );
19
+ emp2.workHours (100 );
20
+
21
+
22
+ std::cout << " You have employees: "
23
+ << emp1.getFullName () << " and "
24
+ << emp2.getFullName () << std::endl;
25
+ PrintPay (emp1);
26
+ PrintPay (emp2);
10
27
}
You can’t perform that action at this time.
0 commit comments