erehh

klasebi, OOP, kompania

May 1st, 2022
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class AbstractEmployee
  7. {
  8.     virtual void AskForPromotion()=0;
  9. };
  10.  
  11. class Employee:AbstractEmployee
  12. {
  13. private:
  14.     string Name;
  15.     string Company;
  16.     int Age;
  17. public:
  18.     void setName(string name)
  19.     {
  20.         Name = name;
  21.     }
  22.     string getName()
  23.     {
  24.         return Name;
  25.     }
  26.     void setCompany(string company)
  27.     {
  28.         Company=company;
  29.     }
  30.     string getCompany()
  31.     {
  32.         return Company;
  33.     }
  34.     void setAge(int age)
  35.     {   if(age>=18)
  36.         Age=age;
  37.     }
  38.     int getAge()
  39.     {
  40.         return Age;
  41.     }
  42.     void IntroduceYourself()
  43.     {
  44.         cout << "Name - " << Name << endl;
  45.         cout << "Company - " << Company << endl;
  46.         cout << "age - " << Age << endl;
  47.         cout << endl;
  48.     }
  49.     Employee(string name, string company, int age)
  50.     {
  51.         Name = name;
  52.         Company = company;
  53.         Age = age;
  54.     }
  55.     void AskForPromotion()
  56.     {
  57.         if (Age > 30)
  58.             cout << Name << " got promoted. " << endl;
  59.         else
  60.             cout << Name << " sorry, no promotion. " << endl;
  61.     }
  62. };
  63.  
  64. int main()
  65. {
  66.     Employee employee1 = Employee("Emily","Amazon",26);
  67.     Employee employee2 = Employee("Nick", "Microsoft", 49);
  68.  
  69.     employee1.AskForPromotion();
  70.     employee2.AskForPromotion();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment