Thread: Help with STL container list for INformation Manager

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    72

    Help with STL container list for INformation Manager

    I'm trying to create a info manager like rolodex.
    Rolodex.cpp
    List() function
    Code:
    void Rolodex::List()
    {
    	list<string>::iterator cIterator;
       for (cIterator = cardlist.begin(); cIterator != cardlist.end();    ++cIterator)
       {
          cout << *cIterator << endl; //outputs its contents
       }
    }//end List Function
    Add() function
    Code:
    void Rolodex::Add(list<Rolocard>& cardlist)
    {
    
    	string first, last, add, occ, phone;
    	
    	cout << "Creating new Card "<< endl;
    	cout << "----------------------"<<endl;
    	cout << "Enter First Name: " << endl;
    	cin >> first;
    	cout << "Enter Last Name: "<< endl;
    	cin >> last;
    	cout << "Enter Address: "<< endl;
    	cin >> add;
    	cout << "Enter Occupation: " << endl;
    	cin >> occ;
    	cout << "Enter Phone Number: " << endl;
    	cin >> phone;
    	Rolocard newcard(first, last, add, occ, phone);	
    	cardlist.push_back(newcard);
    
    	
    }
    private member in rolodex class:
    list <Rolocard> sCard;

    ---------------------------------------------------------
    what is the issue with this code?

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    What is it you are having trouble with? Are you getting compilation errors? Runtime errors? We cant help you without more information.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    72
    I've got to create a rolodex with a container for cards which contains information.
    * list - displays all the cards in the rolodex, in alphabetical order from beginning to end.
    * view - displays the card at the current position.
    * flip - updates the current position to the next card, and displays it. Flipping past the last card wraps around to the first card.
    * search - finds and displays a card, and makes it the current position in the rolodex. This command prompts for the last name for searching. If a matching card is found, it is displayed and is set as the current position. If no matching card is found, the card that immediately follows the lookup name is displayed and set as the current position (e.g. if "H" is entered as the last name, the first card with a last name following "H" in alphabetical order is displayed). If there is no following card, displays "Couldn't find: name"
    * add - adds a new card to the rolodex. Prompts for each field value, reads it, and enters the new card in the correct position in the rolodex (based on alphabetical order). The new card is set as the current position.
    * remove - removes the card at the current position. It displays the card and prompts for a confirmation for removal. The following card is set as the current position.
    * modify - updates the card at the current position. Enters a mode that requests the field to be updated (e.g. phone #), displays the existing value and prompts for the new value, reads it, and updates the card. Continues prompting for additional changes until all changes are done (e.g. a 0 is entered for the field # to change). If the last name is changed, the card must be moved to the correct position in the rolodex (and is set as the current position).
    * quit - exits the program.
    I've already create the rolocard class which holds the information. Now my next step is to create the rolodex class which will manage the information. I can't seem to use the container private member in other member functions

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You need to post more code since there isn't anything wrong with that.

    One question, though, if the list is a member of Rolodex, why do you pass it to the Add method? Shouldn't Add add to the same list that is its member? Naturally you can't access the private member outside of Rolodex (in main, where you might be trying to pass it to the Add method).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    72
    I tried to create a new object to call the Add function but the compiler said that there is no default constructor available
    Code:
    void Rolodex::Add(Rolocard card)
    {
    
    	string first, last, add, occ, phone;
    	
    	cout << "Creating new Card "<< endl;
    	cout << "----------------------"<<endl;
    	cout << "Enter First Name: " << endl;
    	cin >> card.getFirst();
    	cout << "Enter Last Name: "<< endl;
    	cin >> card.getLast();
    	cout << "Enter Address: "<< endl;
    	cin >> card.getAdd();
    	cout << "Enter Occupation: " << endl;
    	cin >> card.getOcc();
    	cout << "Enter Phone Number: " << endl;
    	cin >> card.getPhone();
    	Rolocard NewCard = Rolocard (card.getFirst(), card.getLast(), card.getAdd(), card.getOcc(), card.getPhone());
    	sCard.push_back(NewCard);
    
    	
    }
    I called it in main like this:
    Code:
    int main ()
    {	
    Rolodex Info;
    Rolocard ncard;
    Info.Add(ncard);
    
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    72
    Can somebody help me on this?
    are these two function good?

    list() function
    Code:
    void Rolodex::List()
    {
    	std::ostream_iterator < string > output (cout, "\n");
    	std::copy( rolodex.begin(), rolodex.end(), output);
    }//end List function
    Add() function
    Code:
    void Rolodex::Add()
    {
    	string first, last, add, occ, phone;
    	Rolocard* newcard;
    	cout << "Creating new Card "<< endl;
    	cout << "----------------------"<<endl;
    	cout << "Enter First Name: " << endl;
    	cin >> first;
    	cout << "Enter Last Name: "<< endl;
    	cin >> last;
    	cout << "Enter Address: "<< endl;
    	cin >> add;
    	cout << "Enter Occupation: " << endl;
    	cin >> occ;
    	cout << "Enter Phone Number: " << endl;
    	cin >> phone;
    	newcard = new Rolocard (first, last, add, occ, phone);
    	rolodex.push_back(newcard->cardinfo() );
    	rolodex.sort();
    	
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. Recursion Revisited again, and again!
    By clegs in forum C++ Programming
    Replies: 93
    Last Post: 12-08-2007, 08:02 PM
  3. Resource manager tree
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 09-07-2007, 10:27 PM
  4. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM