Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<conio.h>
  4. #include<limits>
  5. using namespace std;
  6.  
  7.  
  8. class persoana {
  9. string nume;
  10. int tip;
  11. persoana* urm;
  12. public:
  13. persoana(string n, int t) {
  14. nume = n;
  15. tip = t;
  16. urm = NULL;
  17. }
  18. virtual void afis() {
  19. cout << "\nNume: "<<nume;
  20. }
  21. friend class Lista;
  22. };
  23.  
  24. class student : public persoana {
  25. int an;
  26. public:
  27. student(string n, int t, int a) : persoana(n, t) {
  28. an = a;
  29. }
  30. void afis() {
  31. persoana::afis();
  32. cout << "\nAn: " << an;
  33. }
  34. friend class Lista;
  35. };
  36.  
  37. class profesor : public persoana {
  38. string materie;
  39. public:
  40. profesor(string n, int t, string m) : persoana(n, t) {
  41. materie = m;
  42. }
  43. void afis() {
  44. persoana::afis();
  45. cout << "\nMaterie: " << materie;
  46. }
  47. friend class Lista;
  48. };
  49.  
  50. class Supraincarcare {
  51. public:
  52. string nume, materie;
  53. int s;
  54. int tip, an;
  55. friend istream& operator>>(istream& in, Supraincarcare& a);
  56. };
  57.  
  58. istream& operator>>(istream& in, Supraincarcare& a) {
  59. cout << "Alegeti numele: "; cin >> a.nume;
  60. if (a.tip == 0) {
  61. cout << "Alegeti materia: "; cin >> a.materie;
  62. }
  63. else {
  64. cout << "Alegeti anul:"; cin >> a.an;
  65. }
  66. return in;
  67. }
  68. class Lista {
  69. public:
  70. persoana* head;
  71.  
  72. void adaugare(persoana* a) {
  73. persoana* p;
  74. p = head;
  75. if (p == NULL) {
  76. head = a;
  77. }
  78. else{
  79. if (p->nume.compare(a->nume) > 0) {
  80. a->urm = head;
  81. head = a;
  82. }
  83. else {
  84. while (p->urm && p->urm->nume.compare(a->nume)<0)
  85. p = p->urm;
  86. a->urm = p->urm;
  87. p->urm = a;
  88. }
  89. }
  90. }
  91. void stergere(string n) {
  92. persoana* p, * q;
  93. p = q = head;
  94. if (p) {
  95. while (p && p->nume.compare(n) != 0) {
  96. q = p;
  97. p = p->urm;
  98. }
  99. if (p) {
  100. if (p == q) {
  101. head = p->urm;
  102. delete p;
  103. }
  104. else {
  105. q->urm = p->urm;
  106. delete p;
  107. }
  108. }
  109. else
  110. cout << "elementul nu a fost gasit";
  111. }
  112. else
  113. cout << "Lista e nula";
  114. }
  115. void afisare() {
  116. persoana* q;
  117. q = head;
  118. while (q!=NULL) {
  119. q->afis();
  120. q = q->urm;
  121. }
  122. }
  123.  
  124. int cautaremax() {
  125. persoana* q = head;
  126. int max= q->tip;
  127. while (q != NULL) {
  128. if (q->tip > max)
  129. max = q->tip;
  130. q = q->urm;
  131. }
  132. }
  133. };
  134. void introducere(Lista &l, int t) {
  135. Supraincarcare supr;
  136. supr.tip = t;
  137. cin >> supr;
  138. if (supr.tip == 0) {
  139. profesor* p;
  140. p = new profesor(supr.nume, supr.tip, supr.materie);
  141. l.adaugare(p);
  142. }
  143. else {
  144. student* s;
  145. s = new student(supr.nume, supr.tip, supr.an);
  146. l.adaugare(s);
  147. }
  148. }
  149.  
  150.  
  151.  
  152. int main() {
  153. Lista l;
  154. l.head= NULL;
  155. introducere(l, 0);
  156. introducere(l, 1);
  157. introducere(l, 0);
  158. l.stergere("3");
  159. l.afisare();
  160. return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement