Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // Osoba.cpp
  2. #include "Osoba.h"
  3.  
  4. int Osoba::x = 0;
  5.  
  6. Osoba::~Osoba()
  7. {
  8. }
  9.  
  10. void Osoba::setImie(const char* nowe_imie) {
  11. delete[] this->imie;
  12. this->imie = nullptr;
  13. this->imie = new char[strlen(nowe_imie) + 1];
  14. strcpy(this->imie, nowe_imie);
  15. }
  16.  
  17. void Osoba::setNazwisko(const char* nowe_nazwisko) {
  18. delete[] this->nazwisko;
  19. this->nazwisko = nullptr;
  20. this->nazwisko = new char[strlen(nowe_nazwisko) + 1];
  21. strcpy(this->nazwisko, nowe_nazwisko);
  22.  
  23. }
  24.  
  25. Osoba& Osoba::operator=(const Osoba &wzor) {
  26. delete[]imie;
  27. delete[]nazwisko;
  28. imie = nullptr;
  29. nazwisko = nullptr;
  30. imie = new char[strlen(wzor.imie) + 1];
  31. nazwisko = new char[strlen(wzor.nazwisko) + 1];
  32. strcpy(imie, wzor.imie);
  33. strcpy(nazwisko, wzor.nazwisko);
  34. dataurodzenia = wzor.dataurodzenia;
  35. return *this;
  36. }
  37.  
  38. std::istream &operator >>(std::istream &we, Osoba &wzor) {
  39.  
  40. char napis[40];
  41. std::cout << "Podaj imie: "; we >> napis;
  42. wzor.setImie(napis);
  43. std::cout << "Podaj nazwisko: "; we >> napis;
  44. wzor.setNazwisko(napis);
  45. we >> wzor.dataurodzenia;
  46. return we;
  47. }
  48. std::ostream &operator <<(std::ostream &wy, Osoba &wzor) {
  49. wy << wzor.indeks << " " << wzor.imie << " " << wzor.nazwisko << " " << wzor.dataurodzenia;
  50. return wy;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement