Advertisement
Dr4noel

POO

Mar 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #pragma warning (disable 4996)
  2. #include <iostream>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. class Student {
  9. private:
  10. char *nume;
  11. int nota;
  12. public:
  13. //constructor implicit cu parametri impliciti
  14. Student(char *nume = "NA", int nota = 5);
  15.  
  16. //constructor de copiere
  17. Student(const Student &s);
  18.  
  19. //destructor
  20. ~Student();
  21.  
  22. //functie care returneaza numele
  23. char * getNume();
  24.  
  25. //functie care returneaza nota
  26. int getNota();
  27.  
  28. //functie de modificare a numelui
  29. void setNume(char *nume);
  30.  
  31. //functie de modificare a notei
  32. void setNota(int nota);
  33.  
  34. //functie de afisare
  35. void afis();
  36.  
  37. //functie de citire
  38. void citeste();
  39. };
  40.  
  41. class Catalog {
  42. private:
  43. int nr;
  44. Student *s;
  45. public:
  46. Catalog(int n);
  47. ~Catalog();
  48. void afis();
  49. void citeste();
  50. };
  51.  
  52. void main() {
  53. int k;
  54. cout << "Introduceti numarul de studenti: " << endl;
  55. cin >> k;
  56.  
  57. Catalog ceva(k);
  58.  
  59. ceva.citeste();
  60. ceva.afis();
  61.  
  62. _getch();
  63. }
  64.  
  65. Student::Student(char *nume, int nota) {
  66. this->nume = new char[strlen(nume) + 1];
  67. strcpy_s(this->nume, strlen(nume) + 1, nume);
  68. this->nota = nota;
  69. }
  70.  
  71. Student::Student(const Student &v) {
  72. this->nume = new char[strlen(nume) + 1];
  73. strcpy_s(this->nume, strlen(nume) + 1, v.nume);
  74. this->nota = v.nota;
  75. }
  76.  
  77. Student::~Student() {
  78. if (nume != 0)
  79. delete nume;
  80. }
  81.  
  82. char* Student::getNume() {
  83. return nume;
  84. }
  85.  
  86. int Student::getNota() {
  87. return nota;
  88. }
  89.  
  90. void Student::setNume(char * nume) {
  91. this->nume = nume;
  92. }
  93.  
  94. void Student::setNota(int nota) {
  95. this->nota = nota;
  96. }
  97.  
  98. void Student::afis() {
  99. cout << "Studentul " << nume << " are nota " << nota << endl;
  100. }
  101.  
  102. void Student::citeste() {
  103. char n1[30];
  104. cout << endl<< "Introduceti numele studentului: " << endl;
  105. cin >> n1;
  106. nume = new char[strlen(n1) + 1];
  107. strcpy_s(nume, strlen(nume), n1);
  108.  
  109. cout <<endl<< "Introduceti nota studentului: " << endl;
  110. cin >> nota;
  111. }
  112.  
  113. Catalog::Catalog(int nr) {
  114. this->nr = nr;
  115. s = new Student[this->nr];
  116. }
  117.  
  118. Catalog::~Catalog() {
  119. if (s != 0)
  120. delete s;
  121. }
  122.  
  123. void Catalog::citeste() {
  124. for (int i = 0; i < nr; i++) {
  125. s[i].citeste();
  126. }
  127. }
  128.  
  129. void Catalog::afis() {
  130. for (int i = 0; i < nr; i++) {
  131. s[i].afis();
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement