How would I create three empty lists in a program titled Undone, Partially Done, and Done?
How would I create three empty lists in a program titled Undone, Partially Done, and Done?
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.
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.
You said you'd post code, so do it.
> 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.
How would I write the code for deleting an item from any of the three lists?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)
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.
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;}
This needs to be lowercase. C++ is CaSe SeNsItIvE.Code:If
That'll be easy. The lists are currently empty until the user inputs the string to be added.Originally Posted by Daved
Erase??Originally Posted by Daved
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.DoneCode: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 09:34 PM.
>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...
Double Helix STL
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 ;
>> 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.