-
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
-
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::push_back method
Thanx
-
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::dvdArrayList(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::dvdArrayList(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::dvdArrayList()
{
}
dvdArrayList::dvdArrayList(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
-
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
-
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
-
Re: List question
Code tags are easy to use....
[ code ]
//copy and paste your code here
[ /code ]
-
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::deque/std::vector instead of std::list because I think you would be searching the container a lot for specific movies etc.]