here is the prgram for linked list
You can represent an integer with any number of digits by storing the integer as a sequence of digits in a linked list. A more efficient representation will store a larger integer in each node. Design and implement a class for whole number arithmetic in which a number is implemented as a doubly linked list of integers. Each node will hold an integer value less than or equal to 999. The number represented is the concatenation of the numbers in the nodes. For example, if there are four nodes with the four integers 23,7,999, and 0. then this represents the number 23,007,999,000. Note that the number in a node is always considered to be three digits long. If it is not three digits long, then leading zeros are added to make it three digits long. Submitting Your Work Submit your entire directory as a .tar.gz archive, online through Moodle. Double check that you have the right file before you submit. Uploading the wrong file will result in a mark of ZERO for the entire assignment Program Specification: Your class names should match their file names. Use suitable information encapsulation techniques (i.e., data members should be private and a function not changing the object should be constant). Public member functions for the node class should include the following: o A default constructor in which the number is 0. o A parametrized constructor in which the user specifies a whole number less than or equal to 999. You may combine the default and parameterized constructor as one. o Getter and Setter which return and update the data member. Public member functions for the linked_numbers class should include the following: A parametrized constructor in which the user specifies a whole number less than or equal to 999. Getters and Setters which return and update their respective data member values. o append_node to add a new node at the end of the list Overload all the following integer operators to work with your linked_numbers class +, , =,== In main.cpp, do the following: Create 2 linked_numbers objects with the names: number1 and number2 Append nodes with appropriate integer values until number1 equals 23,007,909,999, and number2 equals 6,007,002,009 o Carry out the following operations on the objects: +.. ,,, >= Additional Program Specification All files (.h and.cpp) should include a comment at the top of the file with your name, and a brief description of what the file is for. All functions should be properly documented in the header file, including PRECONDITION and POSTCONDITIONS (with those words). You do not need to include this in the function implementation as well. Your code should include appropriate comments, identifying variables (if needed) and describing what each section of code is doing. All identifiers (function and variable names) should be meaningful. Your code should have proper indentation and spacing. Make your functions minimal -- do not pass in variables that you do not need. Any objects to be passed as parameters should be passed by reference. Make sure to declare object inputs as const where appropriate. Functions which do not modify the object should be const. Expected Output: . number1: 23,007,909,999 number2: 6,007,002,009 number1 + number2: 29,014,912,008 number 1 - number2: 17,000,907,990 number1 == number2: FALSE number1 = number2: TRUE Grading node class linked_numbers class Operator overloading Main program Documentation & formatting 10% 20% 20% 30% 20% *** NOTE: Your code must compile and execute within the laboratory environment. Code that does not compile will result in a mark of ZERO for the entire assignment. *** l Home 8:43 PM 38% Here is the code divided into.h and.cpp files. Class definitions usually are placed into.h files, in this case both the class definition i.e. node and linkedlist are placed in one header file. Rest of the code including body of methods belonging to each class and the main function is part of linkedlist.cpp file. #ifndef _LINKEDLIST_H_ linkedlist.h #define _LINKEDLIST_H_ class node private: int data; node *next; public: node (int); void set (int); int get(); void setNext (node *); node *getNext 0); void showData(); class LinkedList private: node * headNode; node *currentNode; int size; public: Linked List 0; void start (); void next(); int get(); int length(); void add (int d); void update (int d); void remove(); void find (int d); void showList 0); #endif linkedlist.cpp linkedlist.cpp #include
#include "linkedlist.h" using namespace std; /Node class method definitions node::node (int x) { set (x); next = NULL; } void int node::set (int x) node::get() { data = x; return data; } void node * node::setNext (node *ptr) node::getNext () { { next = ptr; return next; } void node::showData() { cout getNext () != NULL) { currentNode = currentNode->getNext (); } int LinkedList::get() { if (currentNode != NULL) { return currentNode->get(); } int LinkedList::length 0) return size; void LinkedList::add (int d) LinkedList::add (int d) { node *newNode = new node (d); if (size == 0) { currentNode = newNode; headNode = newNode; currentNode->setNext (headNode); } else { newNode->setNext (currentNode- >getNext (); currentNode->setNext (newNode); currentNode = newNode; } size++; } void LinkedList::update (int d) { if (currentNode != NULL) { currentNode->set (d); } } void LinkedList::remove() { if (currentNode != NULL) { if (currentNode != headNode) if (currentNode != neadNode) { node *ptr; ptr = headNode; while (ptr->getNext () != currentNode) { ptr = ptr->getNext (); } cout getNext 0->get() setNext (currentNode->getNext 0); currentNode = ptr; size- } else { currentNode = currentNode->getNext 0; node *ptr; ptr = headNode; while (ptr->getNext () != headNode) { ptr = ptr->getNext (); } cout getNext 0->get() setNext (currentNode); headNode = currentNode; size- } } else } } else { cout get() == d) { cout getNext (); } while (ptr != headNode); void LinkedList::showList () node *ptr; ptr = headNode; do 38% Home 8:44 PM ptr->showData(); ptr = ptr->gettext 0 of 1 } while (ptr != headNode); cout > spaces; for (int i = 1; i >x; 1.add (x); } I.showList (); cout 1) { int i; for (i = 0; i =,== In main.cpp, do the following: Create 2 linked_numbers objects with the names: number1 and number2 Append nodes with appropriate integer values until number1 equals 23,007,909,999, and number2 equals 6,007,002,009 o Carry out the following operations on the objects: +.. ,,, >= Additional Program Specification All files (.h and.cpp) should include a comment at the top of the file with your name, and a brief description of what the file is for. All functions should be properly documented in the header file, including PRECONDITION and POSTCONDITIONS (with those words). You do not need to include this in the function implementation as well. Your code should include appropriate comments, identifying variables (if needed) and describing what each section of code is doing. All identifiers (function and variable names) should be meaningful. Your code should have proper indentation and spacing. Make your functions minimal -- do not pass in variables that you do not need. Any objects to be passed as parameters should be passed by reference. Make sure to declare object inputs as const where appropriate. Functions which do not modify the object should be const. Expected Output: . number1: 23,007,909,999 number2: 6,007,002,009 number1 + number2: 29,014,912,008 number 1 - number2: 17,000,907,990 number1 == number2: FALSE number1 = number2: TRUE Grading node class linked_numbers class Operator overloading Main program Documentation & formatting 10% 20% 20% 30% 20% *** NOTE: Your code must compile and execute within the laboratory environment. Code that does not compile will result in a mark of ZERO for the entire assignment. *** l Home 8:43 PM 38% Here is the code divided into.h and.cpp files. Class definitions usually are placed into.h files, in this case both the class definition i.e. node and linkedlist are placed in one header file. Rest of the code including body of methods belonging to each class and the main function is part of linkedlist.cpp file. #ifndef _LINKEDLIST_H_ linkedlist.h #define _LINKEDLIST_H_ class node private: int data; node *next; public: node (int); void set (int); int get(); void setNext (node *); node *getNext 0); void showData(); class LinkedList private: node * headNode; node *currentNode; int size; public: Linked List 0; void start (); void next(); int get(); int length(); void add (int d); void update (int d); void remove(); void find (int d); void showList 0); #endif linkedlist.cpp linkedlist.cpp #include #include "linkedlist.h" using namespace std; /Node class method definitions node::node (int x) { set (x); next = NULL; } void int node::set (int x) node::get() { data = x; return data; } void node * node::setNext (node *ptr) node::getNext () { { next = ptr; return next; } void node::showData() { cout getNext () != NULL) { currentNode = currentNode->getNext (); } int LinkedList::get() { if (currentNode != NULL) { return currentNode->get(); } int LinkedList::length 0) return size; void LinkedList::add (int d) LinkedList::add (int d) { node *newNode = new node (d); if (size == 0) { currentNode = newNode; headNode = newNode; currentNode->setNext (headNode); } else { newNode->setNext (currentNode- >getNext (); currentNode->setNext (newNode); currentNode = newNode; } size++; } void LinkedList::update (int d) { if (currentNode != NULL) { currentNode->set (d); } } void LinkedList::remove() { if (currentNode != NULL) { if (currentNode != headNode) if (currentNode != neadNode) { node *ptr; ptr = headNode; while (ptr->getNext () != currentNode) { ptr = ptr->getNext (); } cout getNext 0->get() setNext (currentNode->getNext 0); currentNode = ptr; size- } else { currentNode = currentNode->getNext 0; node *ptr; ptr = headNode; while (ptr->getNext () != headNode) { ptr = ptr->getNext (); } cout getNext 0->get() setNext (currentNode); headNode = currentNode; size- } } else } } else { cout get() == d) { cout getNext (); } while (ptr != headNode); void LinkedList::showList () node *ptr; ptr = headNode; do 38% Home 8:44 PM ptr->showData(); ptr = ptr->gettext 0 of 1 } while (ptr != headNode); cout > spaces; for (int i = 1; i >x; 1.add (x); } I.showList (); cout 1) { int i; for (i = 0; i