Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- class Osoba{
- public:
- char imie[32];
- char nazw[32];
- };
- class LO{
- private:
- class wezel{
- public:
- Osoba osoba;
- wezel* next;
- };
- wezel* begin;
- wezel* end;
- public:
- LO();
- ~LO();
- bool dodaj(const char* imie, const char* nazw);
- LO(const LO&);
- LO& operator=(const LO&);
- friend std::ostream& operator<<(std::ostream& screen, const LO& write);
- };
- LO::LO(){
- begin=0;
- end=0;
- }
- LO::~LO(){
- while(begin!=0){
- wezel* tmp=begin;
- begin=begin->next;
- delete tmp;
- }
- }
- bool LO::dodaj(const char *imie, const char *nazw) {
- wezel* tmp=new wezel;
- if(end==0 && begin==0){
- tmp->next=0;
- begin=tmp;
- end=tmp;
- }
- else{
- tmp->next=0;
- end->next=tmp;
- end=tmp;
- }
- strcpy(tmp->osoba.imie, imie);
- strcpy(tmp->osoba.nazw, nazw);
- return true;
- }
- LO::LO(const LO& copy){
- wezel* it2=copy.begin;
- while(it2!=0){
- dodaj(it2->osoba.imie, it2->osoba.nazw);
- it2=it2->next;
- }
- }
- LO& LO::operator=(const LO& copy) {
- while(begin!=0){
- wezel* tmp=begin;
- begin=begin->next;
- delete tmp;
- }
- wezel* it2=copy.begin;
- while(it2!=0){
- dodaj(it2->osoba.imie, it2->osoba.nazw);
- it2=it2->next;
- }
- return (*this);
- }
- std::ostream& operator<<(std::ostream& screen, const LO& write){
- wezel* it; //czemu nie widzi wezel?!!!
- it = write.begin;
- while(it!=0){
- screen << "Imie: " << it->osoba.imie<< std::endl;
- screen << "Nazwisko: " << it->osoba.nazw << std::endl;
- it=it->next;
- }
- return screen;
- }
- int main(){
- LO pies;
- pies.dodaj("Kamil", "Sobolewski");
- pies.dodaj("Pawel", "Dzien");
- std::cout << pies;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement