Programming Problem Chapter problem 3, I received a answer with a C++ program us
ID: 3697982 • Letter: P
Question
Programming Problem Chapter problem 3, I received a answer with a C++ program using the class that implements a to-do list. The to-do items will be entered as strings. The user is to prompt to enter command(add and item, mark an item, mark ann item as done or partially done, delete an item and print the list) and data as necessary. One approach is to implement a struct or a class that represents an item and its status, and then modify the List class to work with this struct or class as its item type. Another way would be to keep three lists: Done, Partial, and Undone. When an item is created, it enters the Undone list. Wen its status is changed, it moves to one of the other lists as appropiate. Here is the C++ the previous answer I received:
struct Node
{
int x;
Node *next;
};
// Initialization function which called first Node:
void initNode(struct Node *head, int n)
{
head-> x = n;
}
// To add the Node
void addNode(struct Node *head, int n)
{
struct Node *NewNode = new Node;
NewNode-> next = head;
head = NewNode;
}
// Main program (Implementation)
int _tmain(int argc, _TCHAR* argv[])
{
struct Node *head = new Node;
initNode(head,5);
addNode(head,10);
addNode(head,20);
return 0;
}
Could you use the class approach for this problem and can you add comment what you did.
Thanks
Explanation / Answer
#include #include #include using namespace std; /* * Node Declaration */ struct node { int info; struct node *next; }*start; /* * Class Declaration */ class single_llist { public: node* create_node(int); void insert_begin(); void insert_pos(); void insert_last(); void delete_pos(); void sort(); void search(); void update(); void reverse(); void display(); single_llist() { start = NULL; } }; /* * Main :contains menu */ main() { int choice, nodes, element, position, i; single_llist sl; start = NULL; while (1) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.