Question: In C++ The program reads the first input as the number of integer input values that follow, and then reads and stores that many following

In C++

The program reads the first input as the number of integer input values that follow, and then reads and stores that many following input values into userOwls. Complete the OwlsList class destructor. The destructor prints "In OwlsList destructor", followed by a new line, and then calls the destructor of each node in the linked list.

Ex: If the input is 3 5 9 6, then the output is:

In OwlsList destructor OwlNode with 6 owlets is deallocated. OwlNode with 9 owlets is deallocated. OwlNode with 5 owlets is deallocated.

#include using namespace std;

class OwlNode { public: OwlNode(int owletsValue); ~OwlNode();

int owlets; OwlNode* next; };

OwlNode::OwlNode(int owletsValue) { owlets = owletsValue; }

OwlNode::~OwlNode() { cout << "OwlNode with " << owlets << " owlets is deallocated." << endl; }

class OwlsList { public: OwlsList(); ~OwlsList(); void Prepend(int owletsValue); private: OwlNode* head; };

OwlsList::OwlsList() { head = nullptr; }

/* Your code goes here */

void OwlsList::Prepend(int owletsValue) { OwlNode* newNode = new OwlNode(owletsValue); newNode->next = head; head = newNode; }

int main() { OwlsList* userOwls = new OwlsList(); int inputValue; int owlCount; int i; cin >> owlCount; for (i = 0; i < owlCount; i++) { cin >> inputValue; userOwls->Prepend(inputValue); }

delete userOwls; return 0; }

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 Databases Questions!