Advertisement
Coriic

Untitled

Jun 16th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. class Osoba{
  5. public:
  6. char imie[32];
  7. char nazw[32];
  8. };
  9.  
  10. class LO{
  11. private:
  12. class wezel{
  13. public:
  14. Osoba osoba;
  15. wezel* next;
  16. };
  17. wezel* begin;
  18. wezel* end;
  19. public:
  20. LO();
  21. ~LO();
  22. bool dodaj(const char* imie, const char* nazw);
  23. LO(const LO&);
  24. LO& operator=(const LO&);
  25. friend std::ostream& operator<<(std::ostream& screen, const LO& write);
  26. };
  27.  
  28. LO::LO(){
  29. begin=0;
  30. end=0;
  31. }
  32.  
  33. LO::~LO(){
  34. while(begin!=0){
  35. wezel* tmp=begin;
  36. begin=begin->next;
  37. delete tmp;
  38. }
  39. }
  40.  
  41. bool LO::dodaj(const char *imie, const char *nazw) {
  42. wezel* tmp=new wezel;
  43. if(end==0 && begin==0){
  44. tmp->next=0;
  45. begin=tmp;
  46. end=tmp;
  47. }
  48. else{
  49. tmp->next=0;
  50. end->next=tmp;
  51. end=tmp;
  52. }
  53. strcpy(tmp->osoba.imie, imie);
  54. strcpy(tmp->osoba.nazw, nazw);
  55. return true;
  56. }
  57.  
  58. LO::LO(const LO& copy){
  59. wezel* it2=copy.begin;
  60. while(it2!=0){
  61. dodaj(it2->osoba.imie, it2->osoba.nazw);
  62. it2=it2->next;
  63. }
  64. }
  65.  
  66. LO& LO::operator=(const LO& copy) {
  67. while(begin!=0){
  68. wezel* tmp=begin;
  69. begin=begin->next;
  70. delete tmp;
  71. }
  72. wezel* it2=copy.begin;
  73. while(it2!=0){
  74. dodaj(it2->osoba.imie, it2->osoba.nazw);
  75. it2=it2->next;
  76. }
  77. return (*this);
  78. }
  79.  
  80. std::ostream& operator<<(std::ostream& screen, const LO& write){
  81. wezel* it; //czemu nie widzi wezel?!!!
  82. it = write.begin;
  83. while(it!=0){
  84. screen << "Imie: " << it->osoba.imie<< std::endl;
  85. screen << "Nazwisko: " << it->osoba.nazw << std::endl;
  86. it=it->next;
  87. }
  88. return screen;
  89. }
  90.  
  91. int main(){
  92. LO pies;
  93. pies.dodaj("Kamil", "Sobolewski");
  94. pies.dodaj("Pawel", "Dzien");
  95. std::cout << pies;
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement