Last active
April 20, 2024 14:40
-
-
Save zethon/8ef294dfc16ce3ef302ce180d66e7797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
// Requirements: | |
// * get and set employees first name and last name | |
// * get and set employees manager | |
// * get and set employees salary | |
// * function that returns full name | |
// * function that prints all known/set info about employee | |
// * function that gives a raise to an employee, not above 25% | |
class Employee | |
{ | |
public: | |
Employee() = default; | |
~Employee() = default; | |
std::string& get_firstName() | |
{ | |
return _firstName; | |
} | |
void set_firstName(std::string firstName) | |
{ | |
this->_firstName = firstName; | |
} | |
std::string& getLastName() | |
{ | |
return _lastName; | |
} | |
void set_lastName(std::string lastName) | |
{ | |
this->_lastName = lastName; | |
} | |
// combine the first and last name and return the value | |
std::string& fullName() const | |
{ | |
std::string fullName = _firstName + " " + _lastName; | |
return fullName; | |
} | |
float getSalary() | |
{ | |
return _salary; | |
} | |
void set_salary(double salary) | |
{ | |
this->_salary = salary; | |
} | |
const Employee& getManager() | |
{ | |
return *_manager; | |
} | |
void setManager(Employee* manager) | |
{ | |
this->_manager = manager; | |
} | |
void printInfo() | |
{ | |
std::cout << "First name : " << _firstName << std::endl; | |
std::cout << "Last name : " << _lastName << std::endl; | |
std::cout << "Salary : " << _salary << std::endl; | |
if (_manager) | |
{ | |
std::cout << "Manager : " << _manager->_firstName << " " << _manager->_lastName << std::endl; | |
} | |
} | |
void giveRaise(float percent) | |
{ | |
if (percent > 25) | |
{ | |
std::cout << "Percent too high" << std::endl; | |
} | |
_salary += _salary * percent; | |
} | |
private: | |
std::string _firstName; | |
std::string _lastName; | |
Employee* _manager; | |
double _salary; | |
}; | |
int main(int argc, char** argv) | |
{ | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment