Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<string.h>
  4. using namespace std;
  5. class Carte
  6. {
  7. protected:
  8. char* nume;
  9. char *titlu;
  10. char* editura;
  11. int pagini;
  12.  
  13. public:
  14. Carte()
  15. {
  16. this->nume = NULL;
  17. titlu = NULL;
  18. editura = NULL;
  19. pagini = 0;
  20.  
  21. }
  22. Carte(char *nume, char *titlu, char *editura, int pagini)
  23. {
  24. this->nume = new char[strlen(nume) + 1];
  25. strcpy(this->nume, nume);
  26. this->titlu = new char[strlen(titlu) + 1];
  27. strcpy(this->titlu, titlu);
  28. this->editura = new char[strlen(editura) + 1];
  29. strcpy(this->editura, editura);
  30. this->pagini = pagini;
  31. }
  32.  
  33. Carte(const Carte& copi)
  34. {
  35. nume = new char[strlen(copi.nume) + 1];
  36. nume = copi.nume;
  37. titlu = new char[strlen(copi.titlu) + 1];
  38. editura = new char[strlen(copi.editura) + 1];
  39. titlu = copi.titlu;
  40. editura = copi.editura;
  41. pagini = copi.pagini;
  42. }
  43.  
  44. ~Carte()
  45. {
  46. delete[]nume;
  47. delete[] titlu;
  48. delete[] editura;
  49.  
  50. }
  51.  
  52. Carte operator=(const Carte& ion)
  53. {
  54. delete[] nume;
  55. delete[] editura;
  56. delete[] titlu;
  57. pagini = 0;
  58. nume = new char[strlen(ion.nume) + 1];
  59. nume = ion.nume;
  60. titlu = new char[strlen(ion.titlu) + 1];
  61. editura = new char[strlen(ion.editura) + 1];
  62. titlu = ion.titlu;
  63. editura = ion.editura;
  64. pagini = ion.pagini;
  65. return *this;
  66.  
  67. }
  68.  
  69. void afis()
  70. {
  71. cout << nume << " " << titlu << " " << editura << endl;
  72. cout << pagini << endl;
  73. }
  74.  
  75. /* int operator==(const Carte& ion) const
  76. {
  77. if ((this->pagini != ion.pagini) || (strlen(this->nume) != strlen(ion.nume)) || ((strlen(this->titlu) != strlen(ion.titlu))) || (strlen(this->editura) != strlen(ion.editura)))
  78. return 0;
  79.  
  80. if (strcmp(this->nume, ion.nume)==0)
  81. return 0;
  82. if (strcmp(this->editura, ion.editura) == 0)
  83. return 0;
  84. if (strcmp(this->titlu, ion.titlu) == 0)
  85. return 0;
  86. return 1;
  87.  
  88. }
  89.  
  90. */
  91. friend ostream& operator<<(ostream& out, Carte ion);
  92.  
  93.  
  94.  
  95.  
  96. };
  97. ostream& operator<<(ostream& out, Carte ion)
  98. {
  99. out << ion.nume << ion.editura << ion.titlu << ion.pagini << endl;
  100.  
  101.  
  102.  
  103. return out;
  104. }
  105. int main() {
  106.  
  107. Carte abd("abcd", "iaiad", "asasa", 1000);
  108. Carte x;
  109. x = abd;
  110. x.afis();
  111. // if (x == abd)
  112. // cout << "sunt egale";
  113. //else
  114. //cout << "nu sunt egale";
  115.  
  116. /*char a[10],b[10];
  117. cin >> a >> b;
  118. if (strcmp(a, b) == 1)
  119. cout << "egL";
  120. */
  121. //cout << abd;
  122. system("pause");
  123. return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement