daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. class Persoana {
  8. private:
  9.     string nume;
  10.     int varsta;
  11. public:
  12.     Persoana() {}
  13.     Persoana(string nume, int varsta)
  14.         : nume(nume)
  15.         , varsta(varsta)
  16.         {}
  17.     string getNume() {
  18.         return nume;
  19.     }
  20.     int getVarsta() {
  21.         return varsta;
  22.     }
  23.     void setNume(string nume) {
  24.         this->nume = nume;
  25.     }
  26.     void setVarsta(int varsta) {
  27.         this->varsta = varsta;
  28.     }
  29. };
  30.  
  31. class Angajat : public Persoana {
  32. private:
  33.     string job;
  34. public:
  35.     Angajat() {}
  36.     Angajat(string nume, int varsta, string job)
  37.         : Persoana(nume, varsta)
  38.         , job(job)
  39.         {}
  40.     string getJob() {
  41.         return job;
  42.     }
  43.     string setJob(string job) {
  44.         this->job = job;
  45.     }
  46. };
  47. template <class T>
  48. class Array {
  49. private:
  50.     int no_elements_heap;
  51.     int no_elements;
  52.     T* om;
  53. public:
  54.     Array(int no_elements_heap)
  55.         : no_elements_heap(no_elements_heap)
  56.     {
  57.         no_elements = 0;
  58.         om = new T[no_elements_heap];
  59.     }
  60.    
  61.     void push_back(const T& om) {
  62.         this->om[no_elements++] = om;
  63.     }
  64.  
  65.     void show() {
  66.         for (int iterator = 0; iterator < no_elements; iterator++) {
  67.             cout << om[iterator].getNume() << ' ' << om[iterator].getVarsta() << '\n';
  68.         }
  69.     }
  70.  
  71.     ~Array() {
  72.         delete[] om;
  73.     }
  74. };
  75.  
  76. int main() {
  77.     Persoana p1("Hanna Montana", 28), p2("Gicu", 20), p3("Nelu", 30);
  78.     Angajat a1("Joe", 32, "elev"), a2("Lucky", 12, "animal de companie"), a3("Paco", 22, "student"), a4("Wayne", 26, "profesor");
  79.     //
  80.     Array<Persoana> arr1(3);
  81.     Array<Angajat> arr2(4);
  82.     //in arrayul de persoana pot sa adaug pe langa persoane si angajati
  83.     arr1.push_back(p1);
  84.     arr1.push_back(a3);
  85.     arr1.show();
  86.     //
  87.     arr2.push_back(a1);
  88.     arr2.push_back(a4);
  89.     arr2.show();
  90.     //
  91.     return 0;
  92.  
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top