Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string>
- using namespace std;
- class Persoana {
- private:
- static Persoana *head;
- Persoana *next;
- string nume, prenume, numeLiceu;
- public:
- Persoana(string nume, string prenume, string numeLiceu){
- this->nume = nume;
- this->prenume = prenume;
- this->numeLiceu = numeLiceu;
- this->next = NULL;
- if (head == NULL) {
- head = this;
- return;
- }
- if (head->nume > this->nume) {
- this->next = head;
- head = this;
- return;
- }
- Persoana *q = head;
- while (q->next && q->next->nume < this->nume) q = q->next;
- this->next = q->next;
- q->next = this;
- }
- virtual void Show() {
- cout << "\nNume: "<< nume;
- cout << "\nPrenume: " << prenume;
- cout << "\nNume Liceu: " << numeLiceu;
- }
- static void Showlist() {
- Persoana *q = head;
- while (q) {
- q->Show();
- q = q->next;
- }
- }
- static void Search(string nume) {
- }
- };
- Persoana *Persoana::head = NULL;
- class Profesor : public Persoana {
- private:
- string materie, gradDidactic;
- unsigned short vechime;
- double salar;
- public:
- Profesor(string nume, string prenume, string numeLiceu, string materie, string gradDidactic, unsigned short vechime, double salar) :Persoana(nume, prenume, numeLiceu) {
- this->gradDidactic = gradDidactic;
- this->materie = materie;
- this->vechime = vechime;
- this->salar = salar;
- }
- void Show() {
- Persoana::Show();
- cout << "\nMaterie: " << materie;
- cout << "\nGrad Didactic: " << gradDidactic;
- cout << "\nVechime: " << vechime;
- cout << "\nSalariu: " << salar << endl;;
- }
- };
- class Elev : public Persoana {
- private:
- static Elev *head;
- Elev *next;
- string specializare;
- unsigned short an;
- double mediaGen;
- public:
- Elev(string nume, string prenume, string numeLiceu, string specializare, unsigned short an, double mediaGen) :Persoana(nume, prenume, numeLiceu) {
- this->specializare = specializare;
- this->an = an;
- this->mediaGen= mediaGen;
- this->next = NULL;
- if (head == NULL) {
- head = this;
- return;
- }
- if (head->mediaGen > this->mediaGen) {
- this->next = head;
- head = this;
- return;
- }
- Elev *q = head;
- while (q->mediaGen && q->next->mediaGen < this->mediaGen) q = q->next;
- this->next = q->next;
- q->next = this;
- }
- void Show() {
- Persoana::Show();
- cout << "\nSpecializare: " << specializare;
- cout << "\nAn: " << an ;
- cout << "\nMedia Generala: " << mediaGen<< endl;
- }
- static void Showlist() {
- Elev *q = head;
- while (q) {
- q->Show();
- q = q->next;
- }
- }
- };
- Elev *Elev::head = NULL;
- ostream& operator<<(ostream& iesire, Profesor *P)
- {
- iesire << "Date despre persoana" << endl;
- Persoana::Showlist();
- return iesire;
- }
- ostream& operator<<(ostream& iesire, Elev *E)
- {
- iesire << "Date despre persoana" << endl;
- Persoana::Showlist();
- return iesire;
- }
- istream& operator>>(istream& in, Elev *E)
- {
- string nume, prenume, numeLiceu, specializare;
- unsigned short an;
- double mediaGen;
- cout << "Nume: "; cin >> nume;
- cout << "Prenume: "; cin >> prenume;
- cout << "Liceu: "; cin >> numeLiceu;
- cout << "Specializare: "; cin >> specializare;
- cout << "An: "; cin >> an;
- cout << "Media Generala: "; cin >> mediaGen;
- new Elev(nume, prenume, numeLiceu, specializare, an, mediaGen);
- return in;
- }
- istream& operator>>(istream& in, Profesor *P)
- {
- string nume, prenume, numeLiceu, materie, gradDidactic;
- unsigned short vechime;
- double salar;
- cout << "Nume: "; cin >> nume;
- cout << "Prenume: "; cin >> prenume;
- cout << "Liceu: "; cin >> numeLiceu;
- cout << "Materie: "; cin >> materie;
- cout << "Grad Didactic: "; cin >> gradDidactic;
- cout << "Vechime: "; cin >> vechime;
- cout << "Salariu: "; cin >> salar;
- new Profesor(nume, prenume, numeLiceu, materie, gradDidactic, vechime, salar);
- return in;
- }
- int main() {
- Elev *elev= NULL;
- Profesor *prof= NULL;
- unsigned short opt;
- do {
- cout << "\n0. Iesire";
- cout << "\n1. Citire Persoana";
- cout << "\n2. Afisare Persoana";
- cout << "\n3. Afisare elevi dupa mediaGen";
- cout << "\nOptiunea aleasa: "; cin >> opt;
- system("cls");
- switch (opt)
- {
- case 0: return 0;
- case 1:
- cout << "\nEste elev - 0/ profesor - 1: "; cin >> opt;
- if (opt)
- cin >> prof;
- else
- cin >> elev;
- break;
- case 2:
- cout << prof;
- break;
- case 3:
- Elev::Showlist();
- default:
- break;
- }
- } while (1);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement