CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: List question

  1. #1
    Join Date
    Oct 2006
    Posts
    14

    List question

    Hello everyone,

    quick question. I have a list made up and it can accept the users input. I was wondering if anyone could help me figure out how to add another 'sub item' to the list. I already have it set up for the user to input but need it to go to the same list. Also When I call back to the main menu of my program, and select show list nothing comes up. Any help would be great thanks.



    Zoogy

  2. #2
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: List question

    Can you Show your Code here so anyone can help you.any way for inserting a item in list you simply can use list:ush_back method

    Thanx

  3. #3
    Join Date
    Oct 2006
    Posts
    14

    Re: List question

    This is where the variables are declared




    #include "Dvd.h"
    #include "AddDelete.h"
    #include "Type.h"
    #include "Menu.h"


    add::add()
    // This is where the user inputs the movie title,
    // and the main character. I may add a few more
    // different things for the user to input.
    {
    cout << "\nYou have chosen to add a movie" << endl;
    getline(cin, title);
    cout << endl;
    cout << "Movie title: ";
    getline(cin, title);
    cout << endl;
    cout << "Is this correct for the title: " << title << "\n\n";
    cout << "(Y, N): ";
    cin >> confirm;

    switch (confirm) // Gets the decision of the correct movie
    {
    case 'y':
    case 'Y':
    cout << "Thank You" << endl;
    dvdArrayList:vdArrayList(title);
    menu::menu();
    break;
    case 'n':
    case 'N':
    cout << "Try again" << endl;
    add::add();
    default:
    cout << "Try again" << endl;
    add::add();
    }
    }

    void add::mainCharacter()
    {
    cout << "\n" << endl;
    getline(cin, character);
    cout << "Please enter a main character: ";
    getline(cin, character);
    cout << endl;
    cout << "Is this correct for the main character: " << character << "\n\n";
    cout << "(Y, N): ";
    cin >> confirm;

    switch (confirm) // gets the decision of the correct character
    {
    case 'y':
    case 'Y':
    cout << endl;
    cout << "Thank You" << endl;
    //dvdArrayList:vdArrayList(character);
    break;
    case 'n':
    case 'N':
    cout << endl;
    cout << "Try again" << endl;
    add::add();
    default:
    cout << "Please select again" << endl;
    add::mainCharacter();
    }

    add::rating();
    }

    void add::rating()
    // This is where the user selects the rating of his/her movie
    {
    cout << "Please select the rating by typing the coresponding number" << endl;
    cout << endl;
    cout << "1. G" << endl;
    cout << "2. PG" << endl;
    cout << "3. PG-13" << endl;
    cout << "4. R" << endl;
    cout << "5. Not Rated" << endl;
    cout << "Rating: ";
    cin >> ratings;

    switch (ratings)
    {
    case '1':
    cout << "You have chosen the rating: G" << endl;
    type::type();
    break;
    case '2':
    cout << "You have chosen the rating: PG" << endl;
    type::type();
    break;
    case '3':
    cout << "You have chosen the rating: PG-13" << endl;
    case '4':
    type::type();
    break;
    cout << "You have chosen the rating: R" << endl;
    case '5':
    type::type();
    break;
    cout << "You have chosen the raing: Not Rated" << endl;
    default:
    cout << "Invalid entry!" << endl;
    cout << "Please choose again!" << endl;
    add::rating();
    }

    }








    This is where my list is





    #include "Menu.H"
    #include "Dvd.h"
    dvdArrayList:vdArrayList()
    {
    }
    dvdArrayList:vdArrayList(string title)
    {
    Movie.push_back (title);

    list<string>::iterator iter;

    for(iter = Movie.begin(); iter != Movie.end(); iter++)
    cout << (title) << endl;
    menu::menu();
    }



    The program runs, I just need to figure out how I could make the list accepth two more user inputs, character, and rating. The other problem is that it doesn't keep the input in the list.


    Zoogy

  4. #4
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: List question

    First use Code tags .So anyone can Understand your Question.and Second Follow the given Link So you can feel Comfortable with list

    http://www.oreillynet.com/pub/a/netw...lus-part2.html

    Thanx

  5. #5
    Join Date
    Oct 2006
    Posts
    14

    Re: List question

    Thank you for the site. I will look at it, and post if I have any more questions. How do you use code tags I am unsure.....


    Zoogy

  6. #6
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: List question

    Code tags are easy to use....

    [ code ]
    //copy and paste your code here
    [ /code ]
    Please rate my post if you felt it was helpful

  7. #7
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: List question

    How is the list in question declared? (the list where you want to add 2 more user inputs?)

    Is it just std::list<std::string>? If that is the case, you might need to declare a struct or a class that holds whatever inputs related to one record, say:
    Code:
    //the datatypes are chosen by me, change them accordingly
    struct MovieDetails
    {
         std::string movie_name;
         std::string character;
         double rating;
    };
    And have the list as:
    Code:
    std::list<MovieDetails> movieDetailsList;
    And proceed ahead, creating instances of movie details setting the attributes and pushing into the list. [You might be better off using std:eque/std::vector instead of std::list because I think you would be searching the container a lot for specific movies etc.]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured