Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <iostream>
- using namespace std;
- #define MAX 40
- class Angajat {
- protected:
- char nume[MAX];
- char calificare[MAX];
- float salariu;
- public:
- Angajat(const char *nume = "", const char *calificare = "", float salariu = 0);
- void setNume(const char *nume);
- char* getNume();
- virtual void afisare();
- };
- Angajat::Angajat(const char *nume, const char *calificare, float salariu) {
- strncpy(this -> nume, nume, MAX);
- strncpy(this -> calificare, calificare, MAX);
- this -> salariu = salariu;
- }
- void Angajat::setNume(const char *nume) {
- strncpy(this -> nume, nume, MAX);
- }
- char* Angajat::getNume() {
- return nume;
- }
- void Angajat::afisare() {
- cout<<"Nume: "<<nume<<endl;
- cout<<"Calificare: "<<calificare<<endl;
- cout<<"Salariu: "<<salariu<<endl;
- }
- class SefSectie: public Angajat {
- protected:
- char sectie[MAX];
- public:
- SefSectie(const char *nume = "", const char *calificare = "", float salariu = 0, const char *sectie="");
- void setSectie(const char *sectie);
- char* getSectie();
- void afisare();
- };
- SefSectie::SefSectie(const char *nume, const char *calificare, float salariu, const char *sectie):
- Angajat(nume, calificare, salariu) {
- strncpy(this -> sectie, sectie, MAX);
- }
- void SefSectie::setSectie(const char *sectie) {
- strncpy(this -> sectie, sectie, MAX);
- }
- char* SefSectie::getSectie() {
- return sectie;
- }
- void SefSectie::afisare() {
- Angajat::afisare();
- cout<<"Sectie: "<<sectie<<endl;
- }
- class Director: public Angajat {
- protected:
- float indemnizatie;
- public:
- Director(const char *nume = "", const char *calificare = "", float salariu = 0, float indemnizatie = 0);
- void setSectie(const char *sectie);
- char* getSectie();
- void afisare();
- };
- Director::Director(const char *nume, const char *calificare, float salariu, float indemnizatie):
- Angajat(nume, calificare, salariu) {
- this->indemnizatie = indemnizatie;
- }
- void Director::afisare() {
- Angajat::afisare();
- cout<<"Indemnizatie: "<<indemnizatie<<endl;
- }
- int main() {
- /*
- Angajat a1("Popa", "sudor", 1000);
- a1.afisare();
- SefSectie s1("Iancu", "mester", 2000, "scularie");
- s1.afisare();
- Director d1("Udrea", "inginer", 3000, 15);
- d1.afisare();
- */
- Angajat *a[] = {
- new Director("Udrea", "inginer", 3000, 15),
- new SefSectie("Iancu", "mester", 2000, "scularie"),
- new Angajat("Popa", "sudor", 1000)
- };
- int n = 3;
- for(int i=0; i<n; i++) {
- a[i]->afisare();
- cout<<"------------------------"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement