Lists...

This is a discussion on Lists... within the C++ Programming forums, part of the General Programming Boards category; How would I create three empty lists in a program titled Undone, Partially Done, and Done?...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    20

    Lists...

    How would I create three empty lists in a program titled Undone, Partially Done, and Done?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Could you be a little more vague? I can't quite bring myself to delete the thread due to irrelevance.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    Sorry... here's the assignment, and the code I have so far... (which isn't much)

    Write a program using the List class from this chapter that implements a To-do list. The items in the list will be strings. The user should be prompted to enter a ccommand (add an item, mark an item as done or partially done, delete an item, and print the list.) and data as necessary. Simply storing items in the list is easy, but the List class doesn't directly support the recording of the status each task. There are different ways you might want to go about this. One would be to implement a struct or a class that represents an item and its status, and modify the List class to work with this struct or class as its item type. Another way is to keep three lists: Done, Partial, and Undone. When an item is created, it enters the Undone list. When its status is changed, it moves to one of the other lists as appropiate. Choose the approach that you prefer, and implement the application using appropiate style, effective prompts, and documentation.

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    You said you'd post code, so do it.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    > Write a program using the List class from this chapter that implements a To-do list.
    It's a good job we've all got easy access to that chapter.

    I did this, but more out of curiosity more than anything else.
    Code:
    #include <iostream>
    #include <string>
    #include <map>
    #include <list>
    using namespace std;
    
    typedef list<int> listof;
    typedef map<string,listof> mapof;
    
    int main ( ) {
        mapof lists;
    
        lists["Undone"].push_back(0);
        lists["Done"].push_back(1);
        lists["Done"].push_back(2);
    
        for ( listof::iterator i = lists["Done"].begin();
              i != lists["Done"].end();
              i++ ) {
            cout << *i << endl;
        }
    
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    Code:
         class List
    {
    protected:
         std::list<string> Undone;
         std::list<string> Partially Done;
         std::list<sting> Done;
    public: 
    If( usercommand= Add Item)
              cout << "Enter Item to be added" << end1;
          cin >> AddItem;
          Undone.push_back(AddItem)
    
    void SortedList::Delete( /* in */ ItemType item )
    If(usercommand= Delete Item)
     cout << "Enter item to be deleted" << endl;
    cin >> "Deleteitem
    (Delete the item from any list it is in)
    How would I write the code for deleting an item from any of the three lists?

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    You'd have to iterate through all values in each list comparing the strings until you found the one you want to delete, then use erase to delete it. You could also use a remove algorithm with erase to do it without the loops.

    This is all not very efficient, though. If you need to lookup by value a list is probably not the best data structure.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Love the sloppy indentation. Keep it up.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  9. #9
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Code:
    If
    This needs to be lowercase. C++ is CaSe SeNsItIvE.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    Quote Originally Posted by Daved
    You'd have to iterate through all values in each list comparing the strings until you found the one you want to delete, then use erase to delete it. You could also use a remove algorithm with erase to do it without the loops.

    This is all not very efficient, though. If you need to lookup by value a list is probably not the best data structure.
    That'll be easy. The lists are currently empty until the user inputs the string to be added.

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    Quote Originally Posted by Daved
    You'd have to iterate through all values in each list comparing the strings until you found the one you want to delete, then use erase to delete it. You could also use a remove algorithm with erase to do it without the loops.

    This is all not very efficient, though. If you need to lookup by value a list is probably not the best data structure.
    Erase??

    What would be the syntax or format of the erase command?

    Code:
    #include "list.h"
    #include <iostream>
    
    using namespace std;
    int main()
    {
        cout << "Enter a command (Add Item, Delete Item, Change the item's status, 
                "or print the list):" << end1;
                cin >> usercommand;
    }
        
    
    // Private members of class:
    //    string usercommand
    //    string  addstring
    //    string  deletestring
    //    string  changelist
    //    string  changestring
    //    string  printlist
    
    
    //******************************************************************
    
    List::List()
    
    // Constructor
    
    // Postcondition:
    //     length == 0
    
    {    
        length = 0;
    }
    
    //******************************************************************
    
    
    
    //******************************************************************
    
    void Add Item( /* in */ ItemType& item )
     
    // Inserts item into the SortedList
     
    
    {
        if ( usercommand== Add Item)
              cout << "Enter String to be added:" << end1;
          cin >> AddString;
          Undone.push_back(AddString)
          
    }
    
    
    void Delete Item( /* in */ ItemType item )
    
    // Deletes item from the list, if it is there
    
    
    
    {
        if{usercommand== Delete Item}
           cout << "Enter String to be deleted" << endl;
           cin >> deletestring;
           
        }
    }
    
    //******************************************************************
    
    void List: Change
      
        if(usercommand== Changestatus)
      cout << "Enter the Item you want to change" << end1;
        cin >> changestring;
        "and the status you want it to be:" << end1;
              cin >> changestatus;
        if (changestatus == Partial)
          Partial.push_back(changestring)
          if(changestatus == Done)
          Done.push_back(changestring)
          
      //**************************************************************
      
      void List::print
        cout << "What list would you like to print?" << end1;
        cin >> printlist
        if (printlist == Undone)
          print.Undone
        if(printlist == Partial)
         print.Partail
         if(printlist== Done)
         print.Done
    Code:
    const int MAX_LENGTH =100;  // Maximum possible number of
                                //   components needed
    typedef string ItemType;       // Type of each component
                                //   (a simple type or string class)
    
    class List
    {
    protected:
         std::list<string> Undone;
         std::list<string> PartiallyDone;
         std::list<string> Done;
    public:
        
               void Add Item( /* in */ ItemType& item );
    
            // Inserts item into the Undone List
     
            
    
        void Delete Item( /* in */ ItemType item );
     
            // Deletes an item from any of the three lists... 
              
        void Print ()
        
        void ChangeStatus ()
        
        list();
    Last edited by RVDFan85; 11-27-2006 at 08:34 PM.

  12. #12
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    >If( usercommand== Add Item)

    That is just crying out syntax error. If statements as pointed out by mantd must be lowercase.
    Oh and can a MOD please edit the above un-tagged code...
    I'm just trying to be a better person - My Name Is Earl

  13. #13
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    lowercase if, got it.. It's giving me some weird errors when I try to compile, such as "string is not identified in this scope", for the std::list<string> Undone and it also says that there is a syntax error before the ;

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    >> What would be the syntax or format of the erase command?
    It depends on how you use it. I think you should get your program compiling first, though. There are too many errors there for you to be thinking about adding more code.

    When the code is compiling, look up the list class in your reference book/website to see the erase command. Feel free to ask questions if your attempt doesn't work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 07:10 PM
  2. Question about Linked lists of lists
    By hear_no_evil in forum C Programming
    Replies: 2
    Last Post: 11-08-2004, 01:49 AM
  3. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  4. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 10:32 PM
  5. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21