Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. class Student {
  6. string nume;
  7. int nrNote;
  8. int *note;
  9. public:
  10. Student(string nume, int nrNote, int *note) {
  11. this->nume = nume;
  12. this->nrNote = nrNote;
  13. note = new int[nrNote];
  14. if (note)
  15. {
  16. for (int i = 1; i < nrNote; i++)
  17. this->note[i] = note[i];
  18. }
  19. else
  20. note = NULL;
  21. }
  22.  
  23. Student(const Student& student) { // const sa nu modificam obiectul din greseala in copiere
  24. this->nume = student.nume;
  25. this->nrNote = student.nrNote;
  26. note = new int[nrNote];
  27. if (student.note)
  28. {
  29. for (int i = 1; i < nrNote; i++)
  30. this->note[i] = student.note[i];
  31. }
  32. else
  33. note = NULL;
  34. }
  35.  
  36. ~Student(){
  37. if (note != NULL)
  38. delete[] note;
  39. }
  40.  
  41. Student operator=(const Student& student) {
  42. this->nume = student.nume;
  43. this->nrNote = student.nrNote;
  44. note = new int[nrNote];
  45. if (student.note)
  46. {
  47. for (int i = 1; i < nrNote; i++)
  48. this->note[i] = student.note[i];
  49. }
  50. else
  51. note = NULL;
  52. }
  53.  
  54. };
  55.  
  56. int main() {
  57. int v[] = { 9,10,9,10 };
  58. Student student("Gigel", 4,v);
  59.  
  60. Student s2(student);
  61. Student s3 = student;
  62.  
  63. //s4=s2 s4.operator=(s2)
  64. // supraincarcare
  65. Student s4("Ana", 4, v);
  66. s4 = s2;
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement