Advertisement
madalinaradu

POO Angajat sef sectie

May 27th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #include <string.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. #define MAX 40
  6.  
  7. class Angajat {
  8.   protected:
  9.     char nume[MAX];
  10.     char calificare[MAX];
  11.     float salariu;
  12.   public:
  13.     Angajat(const char *nume = "", const char *calificare = "", float salariu = 0);
  14.     void setNume(const char *nume);
  15.     char* getNume();
  16.     virtual void afisare();
  17. };
  18.  
  19.  
  20.  
  21. Angajat::Angajat(const char *nume, const char *calificare, float salariu) {
  22.   strncpy(this -> nume, nume, MAX);
  23.   strncpy(this -> calificare, calificare, MAX);
  24.   this -> salariu = salariu;
  25. }
  26.  
  27. void Angajat::setNume(const char *nume) {
  28.   strncpy(this -> nume, nume, MAX);
  29. }
  30. char* Angajat::getNume() {
  31.   return nume;
  32. }
  33.  
  34. void Angajat::afisare() {
  35.   cout<<"Nume: "<<nume<<endl;
  36.   cout<<"Calificare: "<<calificare<<endl;
  37.   cout<<"Salariu: "<<salariu<<endl;
  38. }
  39.  
  40. class SefSectie: public Angajat {
  41.   protected:
  42.     char sectie[MAX];
  43.   public:
  44.     SefSectie(const char *nume = "", const char *calificare = "", float salariu = 0, const char *sectie="");
  45.     void setSectie(const char *sectie);
  46.     char* getSectie();
  47.     void afisare();
  48. };
  49.  
  50. SefSectie::SefSectie(const char *nume, const char *calificare, float salariu, const char *sectie):
  51.   Angajat(nume, calificare, salariu) {
  52.   strncpy(this -> sectie, sectie, MAX);
  53. }
  54.  
  55. void SefSectie::setSectie(const char *sectie) {
  56.   strncpy(this -> sectie, sectie, MAX);
  57. }
  58. char* SefSectie::getSectie() {
  59.   return sectie;
  60. }
  61.  
  62. void SefSectie::afisare() {
  63.   Angajat::afisare();
  64.   cout<<"Sectie: "<<sectie<<endl;
  65. }
  66.  
  67. class Director: public Angajat {
  68.   protected:
  69.     float indemnizatie;
  70.   public:
  71.     Director(const char *nume = "", const char *calificare = "", float salariu = 0, float indemnizatie = 0);
  72.     void setSectie(const char *sectie);
  73.     char* getSectie();
  74.     void afisare();
  75. };
  76.  
  77.  
  78. Director::Director(const char *nume, const char *calificare, float salariu, float indemnizatie):
  79.   Angajat(nume, calificare, salariu) {
  80.   this->indemnizatie = indemnizatie;
  81. }
  82.  
  83. void Director::afisare() {
  84.   Angajat::afisare();
  85.   cout<<"Indemnizatie: "<<indemnizatie<<endl;
  86. }
  87.  
  88. int main() {
  89.   /*
  90.   Angajat a1("Popa", "sudor", 1000);
  91.   a1.afisare();
  92.   SefSectie s1("Iancu", "mester", 2000, "scularie");
  93.   s1.afisare();
  94.   Director d1("Udrea", "inginer", 3000, 15);
  95.   d1.afisare();
  96.   */
  97.   Angajat *a[] = {
  98.     new Director("Udrea", "inginer", 3000, 15),
  99.     new SefSectie("Iancu", "mester", 2000, "scularie"),
  100.     new Angajat("Popa", "sudor", 1000)
  101.   };
  102.   int n = 3;
  103.  
  104.   for(int i=0; i<n; i++) {
  105.     a[i]->afisare();
  106.     cout<<"------------------------"<<endl;
  107.   }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement