🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #8689

Re: Nog ��n maal uit de nood helpen.

#8689
From: peterv
Date: Tue, 11 Jun 2002 15:39
595 lines
10291 bytes
Zie oplossing:
Heb main routine wat aangepast.
Mvg,
Peter.

#ifndef __PERSOON_H
#define __PERSOON_H

class Persoon
{
    private:

        int _nummer;
        char _initialen[3];

    public:

        Persoon();

        void setNummer(int nummer);
        void setInitialen(char* initialen);

        int getNummer();
        char* getInitialen();
};

#endif

#include <string.h>
//#include "persoon.h"

Persoon::Persoon()
{
    _nummer = 0;
    strncpy(_initialen,"   ",3);

}

void Persoon::setNummer(int nummer)
{
    _nummer = nummer;
}

void Persoon::setInitialen(char* initialen)
{
    strncpy(_initialen,initialen,3);
}

int Persoon::getNummer()
{
    return _nummer;
}

char* Persoon::getInitialen()
{
    return _initialen;
}

#ifndef __ELEMENT_H
#define __ELEMENT_H
//#include "persoon.h"

class Element
{
    private:
        Persoon* _data;
        Element* _next;

    public:

        //Constructor
        Element(Persoon* data);

        //Opvragen van data
        Persoon* getData();
        Element* getNext();

        //Toevoegen van data
        void setData(Persoon* data);
        void setNext(Element* next);
};

#endif

//#include "element.h"
#include <iostream.h>

Element::Element(Persoon* data)
{
    _data = data;
    _next = NULL;
}

Persoon* Element::getData()
{
    return _data;
}

Element* Element::getNext()
{
    return _next;
}

void Element::setData(Persoon* data)
{
    _data = data;
}

void Element::setNext(Element* next)
{
    _next = next;
}

#ifndef __QUEU_H
#define __QUEU_H

//#include "element.h"

class Queu
{
    private:
        Element* _start;
        Element* _end;

    public:

        //Constructor
        Queu();

        //Destructor
        ~Queu();

        //pop
        Persoon* pop();

        //push
        void push(Persoon* data);

        //controle op elementen
        bool nogElementen();
};

#endif

#include <iostream.h>
//#include "queu.h"

Queu::Queu()
{
    _start = NULL;
    _end = NULL;
}

Persoon* Queu::pop()
{
    Persoon *klant;

    if(_start)
    {

        //Ophalen van de data
        klant = _start -> getData();
        Element* temp = _start;
        _start = _start -> getNext();
        delete temp;
    }
    else
    {
        _end = NULL;
    }

    return klant;
}

void Queu::push(Persoon* data)
{
    Element* el = new Element(data);


    if(_start)
    {
        Element* temp = _end;
        _end = el;
        temp -> setNext(_end);
    }
    else
    {

        _start = el;
        _end = el;
    }
}

bool Queu::nogElementen()
{
    if(_start)
    {
        return true;
    }
    else
    {
        return false;
    }
}

Queu::~Queu()
{
    Element* temp = NULL;

    while(_start)
    {
        temp = _start;
        _start = _start -> getNext();
        delete temp;
    }
}

#include <iostream.h>
#include <string.h>
//#include "queu.h"
//#include "persoon.h"

int main()
{
    Queu Klanten;
    //Persoon Klant;
    Persoon *Klnt;

    //Klnt = &Klant;

    int nummer;
    char initialen[3];
    int i = 0;


    while(i < 3)
    {
        Klnt = new Persoon();
        cout<<"Het klantnummer: ";
        cin>>nummer;
        cin.get();
        Klnt->setNummer(nummer);
        cout<<"De initialen: ";
        cin.get(initialen,3);
        cin.get();
        Klnt->setInitialen(initialen);

        //klant toevoegen aan de lijst
        Klanten.push(Klnt);


        i++;
    }

    cout<<"Klanten uit de lijst halen"<<endl;



    while(Klanten.nogElementen())
    {

        Klnt = Klanten.pop();
        cout<<Klnt->getNummer();
        cout<<Klnt->getInitialen();
        //Klnt = NULL;

        cout<<endl;

    }

    cout<<"bestaat de lijst ja of neen !";
    while(Klanten.nogElementen())
    {
        cout<<"ja"<<endl;
    }

}


"Christof Laeremans" <christof_laeremans@hotmail.com> schreef in bericht
news:B92BDED1.684E%christof_laeremans@hotmail.com...
> Hallo,
>
> "Hier is die C++ zaag weer" ;)
>
> Hier volgt de code van een eenvoudig programma dat gebruikt maakt van een
> lijst van objecten. (Copy Constructor zit er nog niet bij omdat het nog
niet
> al te duidelijk is)
>
> Wie kan me zeggen wat er fout loopt. Want als ik volgende invoer geef
>
> Het klantnummer: 1
> De initialen: a
> Het klantnummer: 2
> De initialen: b
> Het klantnummer: 3
> De initialen: c
> Het klantnummer: 4
> De initialen: d
> Het klantnummer: 5
> De initialen: e
>
> Dan krijg ik deze uitvoer op mijn scherm
> Klanten uit de lijst halen
> 5e
> 5e
> 5e
> 5e
> 5e
>
> Hij blijkt alleen maar het laaste element te poppen
>
> Alvast bedankt voor degene die me wil/kan helpen.
>
> Mvg,
>
> Christof Laeremans
>
> Code
> #ifndef __PERSOON_H
> #define __PERSOON_H
>
> class Persoon
> {
>     private:
>
>         int _nummer;
>         char _initialen[3];
>
>     public:
>
>         Persoon();
>
>         void setNummer(int nummer);
>         void setInitialen(char* initialen);
>
>         int getNummer();
>         char* getInitialen();
> };
>
> #endif
>
> #include <string.h>
> #include "persoon.h"
>
> Persoon::Persoon()
> {
>     _nummer = 0;
>     strncpy(_initialen,"   ",3);
>
> }
>
> void Persoon::setNummer(int nummer)
> {
>     _nummer = nummer;
> }
>
> void Persoon::setInitialen(char* initialen)
> {
>     strncpy(_initialen,initialen,3);
> }
>
> int Persoon::getNummer()
> {
>     return _nummer;
> }
>
> char* Persoon::getInitialen()
> {
>     return _initialen;
> }
>
> #ifndef __ELEMENT_H
> #define __ELEMENT_H
> #include "persoon.h"
>
> class Element
> {
>     private:
>         Persoon* _data;
>         Element* _next;
>
>     public:
>
>         //Constructor
>         Element(Persoon* data);
>
>         //Opvragen van data
>         Persoon* getData();
>         Element* getNext();
>
>         //Toevoegen van data
>         void setData(Persoon* data);
>         void setNext(Element* next);
> };
>
> #endif
>
> #include "element.h"
> #include <iostream.h>
>
> Element::Element(Persoon* data)
> {
>     _data = data;
>     _next = NULL;
> }
>
> Persoon* Element::getData()
> {
>     return _data;
> }
>
> Element* Element::getNext()
> {
>     return _next;
> }
>
> void Element::setData(Persoon* data)
> {
>     _data = data;
> }
>
> void Element::setNext(Element* next)
> {
>     _next = next;
> }
>
> #ifndef __QUEU_H
> #define __QUEU_H
>
> #include "element.h"
>
> class Queu
> {
>     private:
>         Element* _start;
>         Element* _end;
>
>     public:
>
>         //Constructor
>         Queu();
>
>         //Destructor
>         ~Queu();
>
>         //pop
>         Persoon* pop();
>
>         //push
>         void push(Persoon* data);
>
>         //controle op elementen
>         bool nogElementen();
> };
>
> #endif
>
> #include <iostream.h>
> #include "queu.h"
>
> Queu::Queu()
> {
>     _start = NULL;
>     _end = NULL;
> }
>
> Persoon* Queu::pop()
> {
>     Persoon *klant;
>
>     if(_start)
>     {
>
>         //Ophalen van de data
>         klant = _start -> getData();
>         Element* temp = _start;
>         _start = _start -> getNext();
>         delete temp;
>     }
>     else
>     {
>         _end = NULL;
>     }
>
>     return klant;
> }
>
> void Queu::push(Persoon* data)
> {
>     Element* el = new Element(data);
>
>
>     if(_start)
>     {
>         Element* temp = _end;
>         _end = el;
>         temp -> setNext(_end);
>     }
>     else
>     {
>
>         _start = el;
>         _end = el;
>     }
> }
>
> bool Queu::nogElementen()
> {
>     if(_start)
>     {
>         return true;
>     }
>     else
>     {
>         return false;
>     }
> }
>
> Queu::~Queu()
> {
>     Element* temp = NULL;
>
>     while(_start)
>     {
>         temp = _start;
>         _start = _start -> getNext();
>         delete temp;
>     }
> }
>
> #include <iostream.h>
> #include <string.h>
> #include "queu.h"
> #include "persoon.h"
>
> int main()
> {
>     Queu Klanten;
>     Persoon Klant;
>     Persoon *Klnt;
>
>     Klnt = &Klant;
>
>     int nummer;
>     char initialen[3];
>     int i = 0;
>
>
>     while(i < 5)
>     {
>         Klnt = NULL;
>         cout<<"Het klantnummer: ";
>         cin>>nummer;
>         cin.get();
>         Klant.setNummer(nummer);
>         cout<<"De initialen: ";
>         cin.get(initialen,3);
>         cin.get();
>         Klant.setInitialen(initialen);
>
>         //klant toevoegen aan de lijst
>         Klanten.push(Klnt);
>
>
>         i++;
>     }
>
>     cout<<"Klanten uit de lijst halen"<<endl;
>
>
>
>     while(Klanten.nogElementen())
>     {
>
>         Klnt = Klanten.pop();
>         cout<<Klant.getNummer();
>         cout<<Klant.getInitialen();
>         Klnt = NULL;
>
>         cout<<endl;
>
>     }
>
>     cout<<"bestaat de lijst ja of neen !";
>     while(Klanten.nogElementen())
>     {
>         cout<<"ja"<<endl;
>     }
>
> }
>
>
>
Technical Details
Message-ID: <3d0619c5$0$8173$ba620e4c@news.skynet.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!nntp.cs.ubc.ca!skynet.be!skynet.be!louie!not-for-mail
References: <B92BDED1.684E%christof_laeremans@hotmail.com>

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit
X-Google-Thread: fcea4,d75aeeec4e01f9d8
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2002-06-11 08:39:52 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!nntp.cs.ubc.ca!skynet.be!skynet.be!louie!not-for-mail
From: "peterv" <petervu@skynet.Be>
Newsgroups: be.comp.programming
References: <B92BDED1.684E%christof_laeremans@hotmail.com>
Subject: Re: Nog ��n maal uit de nood helpen.
Date: Tue, 11 Jun 2002 17:39:40 +0200
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Lines: 597
Message-ID: <3d0619c5$0$8173$ba620e4c@news.skynet.be>
Organization: -= Skynet Usenet Service =-
NNTP-Posting-Host: 217.136.91.214
X-Trace: 1023809990 reader0.news.skynet.be 8173 217.136.91.214
X-Complaints-To: abuse@skynet.be