Question: C + + please You may use the code in the supplied assn 2 Test.cpp file to test these problems. You do NOT need to
C please
You may use the code in the supplied assnTest.cpp file to test these problems. You do NOT need to turn
in the assnTest.cpp file with your assignment. Uncomment lines in main to run tests.
Write a recursive function addCommas that expects a nonnegative integer the data type to use is
unsigned long long int, which can hold any integer up to about digits long returns nothing, and
outputs to the screen the number written with commas. For example, addCommas will
output to the screen Getting full credit means handling ALL possible input values so that
they output correctly no leading zeroes at the very front, but exactly three digits between commas after
that. NOTE: do NOT try to implement tail recursion for this; it'll only make it more complicated :
HINTS: A division operation that stores its result in an int will truncate the result.
For example, the statement int n ; will result in n being set to the value
Also, remember that the operator modulo gives you the remainder of a division. For example, the
statement int r ; will result in r being set to the value
The line #include allows use of the following library functions to print a number n including
leading zeroes when n has less than three digits. This code has been tested in CS your IDE may vary!
cout setfill setw n;
Examine the definition of the provided C classes DoublyLinkedList and DLLNode.
Create and thoroughly test new methods named addToDLLHeaddouble el and
double deleteFromDLLHead that insert and delete from the doublylinked list at the head, similar to how
the existing methods addToDLLTaildouble el and double deleteFromDLLTail do at the DLLs tail.
Test the methods thoroughly to make sure they perform correctly in all cases on empty lists, on lists with
only one item, and on lists with multiple items
Submit the modified files assnh and assncpp containing the code added for both problems. There is
no need to submit the testing file.
assncpp
#include
#include
#include
#include
#include "assnh
PROBLEM PLACE CODE HERE
void addCommasunsigned long long int theNumber
PROBLEM
Adapted from code written and posted by Dr Rick Coleman,
University of AlabamaHuntsville,
CONSTRUCTORS
DoublyLinkedList::DoublyLinkedList
headPtr NULL;
tailPtr NULL;
OTHER METHODS
void DoublyLinkedList::addToDLLTaildouble el
if tailPtr NULL If DLL is nonempty
tailPtr new DLLNodeeltailPtr; Allocate new DLLNode
tailPtrprevPtrnextPtr tailPtr; Link new node to tail of DLL
else If DLL is empty
headPtr new DLLNodeel; Allocate new DLLNode
tailPtr headPtr; Node is first in the DLL so it
is both head and tail
double DoublyLinkedList::deleteFromDLLTail
double el tailPtrinfo; Get value of node to be deleted
if tailPtr NULL
throwEMPTY; Return an error condition
else if headPtr tailPtr If only DLLNode in the DLL
delete headPtr; Deallocate DLLNode
headPtr NULL; Set both head and tail to values for
tailPtr NULL; a DLL with no nodes
else If more than one DLLNode in DLL
tailPtr tailPtrprevPtr; Move tail to previous DLLNode
delete tailPtrnextPtr; Deallocate DLLNode
tailPtrnextPtr NULL; Set next of new last DLLNode to NULL
return el; Return value in deleted DLLNode
#include
#include
#include
#include
#include
#include
#include "assnh
using namespace std;
int main
cout boolalpha;
UNCOMMENT the following code when you're ready to
run tests
cout endl TESTING addCommas endl;
unsigned long long int initialn;
cout "Please enter a nonnegative integer value: ;
cin initialn;
cout "The number with commas is: ;
addCommasinitialn;
cout
;
cout TESTING Class DoublyLinkedList endl;
double el; Place to hold a node's value
cout "Simple DLL Demonstration
;
cout "Creating a DLL
;
DoublyLinkedList theDLLPtr new DoublyLinkedList; Create a DLL object
cout DLL created...
;
Test Insert and Delete methods
el ;
cout "Inserting value el at end of DLL
;
theDLLPtr addToDLLTailel;
el ;
cout "Inserting value el at end of DLL
;
theDLLPtr addToDLLTailel;
el ;
cout "Inserting value el ll at end of DLL
;
theDLLPtr addToDLLTailel;
el ;
cout "Inserting value el at end of DLL
;
theDLLPtraddToDLLTailel;
el ;
cout "Inserting value el
cout ll "Deleting from tail of DLL
;
el theDLLPtrdeleteFromDLLTail;
cout & "Got bac
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
