Skip to content

Commit c130fef

Browse files
committed
Updating the in class demo
1 parent ff07f40 commit c130fef

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

InClassBasicEmployee/BasicEmployee.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,32 @@ BasicEmployee::~BasicEmployee()
1010
{
1111
std::cout << "***BasicEmployee destructor***" << std::endl;
1212
}
13-
std::string BasicEmployee::getFirstName()
13+
std::string BasicEmployee::getFirstName() const
1414
{
1515
return FirstName;
1616
}
17-
std::string BasicEmployee::getLastName()
17+
std::string BasicEmployee::getLastName() const
1818
{
1919
return LastName;
2020
}
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+
}

InClassBasicEmployee/BasicEmployee.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ class BasicEmployee
77
{
88
public:
99
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+
1218
virtual ~BasicEmployee();
1319
private:
1420
std::string FirstName;
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
#include "BasicEmployee.hpp"
22
#include <iostream>
3+
#include <tuple>
34

45

6+
void PrintPay(BasicEmployee& emp)
7+
{
8+
std::cout << emp.getFullName() << " is payed " << emp.getPaycheck() << std::endl;
9+
}
510
int main(void)
611
{
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);
1027
}

0 commit comments

Comments
 (0)