|
-
December 7th, 2006, 08:56 PM
#1
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
-
December 7th, 2006, 11:00 PM
#2
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
-
December 7th, 2006, 11:08 PM
#3
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
-
December 7th, 2006, 11:13 PM
#4
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
-
December 7th, 2006, 11:44 PM
#5
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
-
December 8th, 2006, 01:13 AM
#6
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
-
December 8th, 2006, 02:52 AM
#7
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.]
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|