Advertisement
Alx09

Untitled

Nov 23rd, 2020
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Persoana {
  7. private:
  8.     static Persoana *head;
  9.     Persoana *next;
  10.     string nume, prenume, numeLiceu;
  11. public:
  12.     Persoana(string nume, string prenume, string numeLiceu){
  13.         this->nume = nume;
  14.         this->prenume = prenume;
  15.         this->numeLiceu = numeLiceu;
  16.         this->next = NULL;
  17.         if (head == NULL) {
  18.             head = this;
  19.             return;
  20.         }
  21.         if (head->nume > this->nume) {
  22.             this->next = head;
  23.             head = this;
  24.             return;
  25.         }
  26.         Persoana *q = head;
  27.         while (q->next && q->next->nume < this->nume) q = q->next;
  28.         this->next = q->next;
  29.         q->next = this;
  30.     }
  31.     virtual void Show() {
  32.         cout << "\nNume: "<< nume;
  33.         cout << "\nPrenume: " << prenume;
  34.         cout << "\nNume Liceu: " << numeLiceu;
  35.     }
  36.     static void Showlist() {
  37.         Persoana *q = head;
  38.         while (q) {
  39.             q->Show();
  40.             q = q->next;
  41.         }
  42.     }
  43.     static void Search(string nume) {
  44.  
  45.     }
  46. };
  47. Persoana *Persoana::head = NULL;
  48. class Profesor : public Persoana {
  49. private:
  50.     string materie, gradDidactic;
  51.     unsigned short vechime;
  52.     double salar;
  53. public:
  54.     Profesor(string nume, string prenume, string numeLiceu, string materie, string gradDidactic, unsigned short vechime, double salar) :Persoana(nume, prenume, numeLiceu) {
  55.         this->gradDidactic = gradDidactic;
  56.         this->materie = materie;
  57.         this->vechime = vechime;
  58.         this->salar = salar;
  59.     }
  60.      void Show() {
  61.         Persoana::Show();
  62.         cout << "\nMaterie: " << materie;
  63.         cout << "\nGrad Didactic: " << gradDidactic;
  64.         cout << "\nVechime: " << vechime;
  65.         cout << "\nSalariu: " << salar << endl;;
  66.     }
  67.    
  68. };
  69.  
  70. class Elev : public Persoana {
  71. private:
  72.     static Elev *head;
  73.     Elev *next;
  74.     string specializare;
  75.     unsigned short an;
  76.     double mediaGen;
  77. public:
  78.     Elev(string nume, string prenume, string numeLiceu, string specializare, unsigned short an, double mediaGen) :Persoana(nume, prenume, numeLiceu) {
  79.         this->specializare = specializare;
  80.         this->an = an;
  81.         this->mediaGen= mediaGen;
  82.         this->next = NULL;
  83.         if (head == NULL) {
  84.             head = this;
  85.             return;
  86.         }
  87.         if (head->mediaGen > this->mediaGen) {
  88.             this->next = head;
  89.             head = this;
  90.             return;
  91.         }
  92.         Elev *q = head;
  93.         while (q->mediaGen  && q->next->mediaGen < this->mediaGen) q = q->next;
  94.         this->next = q->next;
  95.         q->next = this;
  96.     }
  97.     void Show() {
  98.         Persoana::Show();
  99.         cout << "\nSpecializare: " << specializare;
  100.         cout << "\nAn: " << an ;
  101.         cout << "\nMedia Generala: " << mediaGen<< endl;
  102.        
  103.     }
  104.     static void Showlist() {
  105.         Elev *q = head;
  106.         while (q) {
  107.             q->Show();
  108.             q = q->next;
  109.         }
  110.     }
  111. };
  112. Elev *Elev::head = NULL;
  113.  
  114. ostream& operator<<(ostream& iesire, Profesor *P)
  115. {
  116.     iesire << "Date despre persoana" << endl;
  117.     Persoana::Showlist();
  118.     return iesire;
  119. }
  120. ostream& operator<<(ostream& iesire, Elev *E)
  121. {
  122.     iesire << "Date despre persoana" << endl;
  123.     Persoana::Showlist();
  124.     return iesire;
  125. }
  126. istream& operator>>(istream& in, Elev *E)
  127. {
  128.     string nume, prenume, numeLiceu, specializare;
  129.     unsigned short an;
  130.     double mediaGen;
  131.     cout << "Nume: "; cin >> nume;
  132.     cout << "Prenume: "; cin >> prenume;
  133.     cout << "Liceu: "; cin >> numeLiceu;
  134.     cout << "Specializare: "; cin >> specializare;
  135.     cout << "An: "; cin >> an;
  136.     cout << "Media Generala: "; cin >> mediaGen;
  137.     new Elev(nume, prenume, numeLiceu, specializare, an, mediaGen);
  138.     return in;
  139. }
  140. istream& operator>>(istream& in, Profesor *P)
  141. {
  142.     string nume, prenume, numeLiceu, materie, gradDidactic;
  143.     unsigned short vechime;
  144.     double salar;
  145.     cout << "Nume: "; cin >> nume;
  146.     cout << "Prenume: "; cin >> prenume;
  147.     cout << "Liceu: "; cin >> numeLiceu;
  148.     cout << "Materie: "; cin >> materie;
  149.     cout << "Grad Didactic: "; cin >> gradDidactic;
  150.     cout << "Vechime: "; cin >> vechime;
  151.     cout << "Salariu: "; cin >> salar;
  152.     new Profesor(nume, prenume, numeLiceu, materie, gradDidactic, vechime, salar);
  153.     return in;
  154. }
  155.  
  156. int main() {
  157.     Elev *elev= NULL;
  158.     Profesor *prof= NULL;
  159.     unsigned short opt;
  160.    
  161.     do {
  162.         cout << "\n0. Iesire";
  163.         cout << "\n1. Citire Persoana";
  164.         cout << "\n2. Afisare Persoana";
  165.         cout << "\n3. Afisare elevi dupa mediaGen";
  166.         cout << "\nOptiunea aleasa: "; cin >> opt;
  167.        
  168.         system("cls");
  169.         switch (opt)
  170.         {
  171.         case 0: return 0;
  172.         case 1:
  173.             cout << "\nEste elev - 0/ profesor - 1: "; cin >> opt;
  174.             if (opt)
  175.                 cin >> prof;
  176.             else
  177.                 cin >> elev;
  178.             break;
  179.         case 2:
  180.             cout << prof;
  181.             break;
  182.        
  183.         case 3:
  184.             Elev::Showlist();
  185.  
  186.         default:
  187.             break;
  188.         }
  189.     } while (1);
  190.    
  191.     system("pause");
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement