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 assn2Test.cpp file to test these problems. You do NOT need to turn
in the assn2Test.cpp file with your assignment. Uncomment lines in main() to run tests.
Write a recursive function addCommas that expects a non-negative integer (the data type to use is
unsigned long long int, which can hold any integer up to about 20 digits long), returns nothing, and
outputs to the screen the number written with commas. For example, addCommas(9008007006) will
output to the screen 9,008,007,006. 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 =3754/1000; will result in n being set to the value 3.
Also, remember that the % operator modulo gives you the remainder of a division. For example, the
statement int r =3754%1000; will result in r being set to the value 754.
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 CS50 your IDE may vary!
cout setfill('0') setw(3) n;
Examine the definition of the provided C++ classes DoublyLinkedList and DLLNode.
Create and thoroughly test new methods named addToDLLHead(double el) and
double deleteFromDLLHead() that insert and delete from the doubly-linked list at the head, similar to how
the existing methods addToDLLTail(double el) and double deleteFromDLLTail() do at the DLL's 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 assn2.h and assn2.cpp containing the code added for both problems. There is
no need to submit the testing file.
assn2.cpp
#include
#include
#include
#include
#include "assn2.h"
// PROBLEM 1- PLACE CODE HERE
// void addCommas(unsigned long long int theNumber){
//
//}
// PROBLEM 2
//---------------------------------------------------------------
// Adapted from code written and posted by Dr. Rick Coleman,
// University of Alabama-Huntsville, 2002
//---------------------------------------------------------------
// CONSTRUCTOR(S)
DoublyLinkedList::DoublyLinkedList(){
headPtr = NULL;
tailPtr = NULL;
}
// OTHER METHODS
void DoublyLinkedList::addToDLLTail(double el){
if (tailPtr != NULL){// If DLL is non-empty
tailPtr = new DLLNode(el,0,tailPtr); // Allocate new DLLNode
tailPtr->prevPtr->nextPtr = tailPtr; // Link new node to tail of DLL
}
else {// If DLL is empty
headPtr = new DLLNode(el); // Allocate new DLLNode
tailPtr = headPtr; // Node is first in the DLL, so it
// is both head and tail
}
}
double DoublyLinkedList::deleteFromDLLTail(){
double el = tailPtr->info; // Get value of node to be deleted
if (tailPtr == NULL)
throw("EMPTY"); // 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 = tailPtr->prevPtr; // Move tail to previous DLLNode
delete tailPtr->nextPtr; // Deallocate DLLNode
tailPtr->nextPtr = NULL; // Set next of new last DLLNode to NULL
}
return el; // Return value in deleted DLLNode
}
```
#include
#include
#include
#include
#include
#include
#include "assn2.h"
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 initial_n;
// cout "Please enter a non-negative integer value: ";
// cin >> initial_n;
// cout "The number with commas is: ";
// addCommas(initial_n);
// 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 =100;
cout "Inserting value " el " at end of DLL
";
theDLLPtr -> addToDLLTail(el);
el =200;
cout "Inserting value " el " at end of DLL
";
theDLLPtr -> addToDLLTail(el);
el =300;
cout "Inserting value " el \ll" at end of DLL
";
theDLLPtr ->addToDLLTail(el);
el =400;
cout "Inserting value " el " at end of DLL
";
theDLLPtr->addToDLLTail(el);
el =500;
cout "Inserting value " el ```
cout \ll "Deleting from tail of DLL
";
el = theDLLPtr->deleteFromDLLTail();
cout & "Got bac
C + + please You may use the code in the supplied

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!