Support_needed_regarding_failure_"doest not name a type"
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Support_needed_regarding_failure_"doest not name a type"

  1. #1
    Join Date
    Apr 2017
    Posts
    3

    Support_needed_regarding_failure_"doest not name a type"

    Hello,

    could you support me in the failures of this task, I have included also the actual failures in Word-Doc.

    Thank you in advance,

    Code:
    /*######################################################
         Einsendeaufgabe 5.2
    ###################################################### */
    
    /* ##################################
        Doppelt verkettete Liste
       ################################## */
    
    #include <iostream>
    using namespace std;
    
    //Die Struktur für die Listenelemente
    struct listenelement
        {
        string daten;
        listenelement* next;
        listenelement* last;
        };
    
    listenelement* listenanfang;
    listenelement* listenende;
    listenelement* hilfszeiger;
    
    
    //Eine Funktion zum Anhängen von Elementen an die Liste
    void anhaengen(string datenneu)
        {
        hilfszeiger = listenanfang;
        while (hilfszeiger->next != nullptr)
               hilfszeiger = hilfszeiger->next;
        }
    
        hilfszeiger->next = new(listenelement);
        listenelement* bisherLetzter = hilfszeiger;
        hilfszeiger = hilfszeiger->next;
    
        strcpy(hilfszeiger->daten,datenneu);
        hilfszeiger->next = NULL;
        hilfszeiger->last = bisherLetzter;
        listenende = hilfszeiger;
    }
    
    
    //Eine Funktion zum Ausgeben aller Elemente
    void ausgeben()
        {
        hilfszeiger = listenanfang;
        cout << hilfszeiger->daten << '\n';
    
        while (hilfszeiger->next != nullptr)
            {
            hilfszeiger = hilfszeiger->next;
            cout << hilfszeiger->daten << '\n';
            }
        }
    
    
    void ausgaberueckwaerts() {
    
            hilfszeiger = listenende;
    
            cout <<hilfszeiger->daten<<"\n";
    
            while (hilfszeiger->last != NULL) {
    
             hilfszeiger = hilfszeiger->last;
             cout << hilfszeiger->daten << "\n";
             }
    
    }
    
    void initialisieren() {
    
            listenanfang = new(listenelement);
            listenanfang->next = NULL;
            listenanfang->last = NULL;
            listenende = listenanfang;
            strcpy(listenanfang->daten,"Element 0");
    }
    
    //die Liste leeren und Speicher freigeben
    void ende()
        {
        while (listenanfang != nullptr)
            {
            hilfszeiger = listenanfang;
            listenanfang = listenanfang->next;
            delete(hilfszeiger);
            }
        }
    
    int main ()
        {
        initialisieren();
        anhaengen("Element 1");
        anhaengen("Element 2");
        anhaengen("Element 3");
        ausgeben();
        ausgaberueckwaerts();
        ende();
    
        return 0;
        }
    Attached Files Attached Files
    Last edited by 2kaud; April 20th, 2017 at 01:43 PM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,452

    Re: Support_needed_regarding_failure_"doest not name a type"

    When posting code, please use code tags so that code is readable. Go Advanced, select the formatted code and click '#'.

    Also it isn't recommended that .doc file etc are attached as these could contain viruses etc. If you need to attach a file - as opposed to pasting the required text which is recommended - can I suggest just a plain .txt file.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,452

    Re: Support_needed_regarding_failure_"doest not name a type"

    Code:
        while (hilfszeiger->next != nullptr)
               hilfszeiger = hilfszeiger->next;
        }
    Shouldn't this be
    Code:
        while (hilfszeiger->next != nullptr) {
               hilfszeiger = hilfszeiger->next;
        }
    Also
    Code:
    strcpy(hilfszeiger->daten, datenneu);
    as both are of type string, this should be
    Code:
    hilfszeiger->daten = datenneu;
    and similar for other like statements.

    You also need a #include <string> as well.

    You are also sometimes using NULL and sometimes using nullptr for when no valid pointer is specified. These should be nullptr not NULL.
    Last edited by 2kaud; April 20th, 2017 at 01:59 PM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  4. #4
    Join Date
    Apr 2017
    Posts
    3

    Re: Support_needed_regarding_failure_"doest not name a type"

    Hello,

    thank you very much for your quick answers, I corrected the code and it works.
    Yes, I should just include the code in txt file or directly.

    Thanks in advance,
    cprogcoder

  5. #5
    Join Date
    Apr 2017
    Posts
    3

    Re: Support_needed_regarding_failure_"doest not name a type"

    I am also an newcomer in C++ Programming. I think I would use this forum for further questions.

    cprogcoder

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)