Question: In C++. Just complete the code where it says Your code here. You do not need to run it. Thanks /* *Purpose: Class for inventory

In C++.

Just complete the code where it says "Your code here". You do not need to run it. Thanks

/* *Purpose: Class for inventory management using a splay tree map to track entries (string key, integer amount/value) */ class SplayTreeInventory { private: SplayTreeMap* stmap;

public: int numProducts(); int available(string id); int size(); void into(string id, int amount); void out(string id, int amount); void printProduct(string id); void printTree(); void printAll(); void printAllHelper(Node* s); void printSize(); // constructor SplayTreeInventory() : stmap(new SplayTreeMap()) {}

};

// OUTPUT: number of different items in inventory int SplayTreeInventory::numProducts() { return this->stmap->size(); }

// INPUT: a string key id // OUTPUT: the value of the entry (amount) corresponding to the input key, if the entry exists // return 0 otherwise // PRECONDITION: // POSTCONDITION: int SplayTreeInventory::available(string id) { // Your code here }

// INPUT: string key id, integer value // PRECONDITION: // POSTCONDITION: void SplayTreeInventory::into(string id, int amount) { // Your code here }

// INPUT: string key id, integer value // PRECONDTION: // POSTCONDITION: void SplayTreeInventory::out(string id, int amount) { // Your code here }

// PRECONDITION: // POSTCONDITION: // OUTPUT: total number of items in the inventory int SplayTreeInventory::size() { // Your code here }

// OUTPUT: string representation of an entry with a specified key id void SplayTreeInventory::printProduct(string id) { cout << id << ": " << this->available(id) << endl; }

// helper function to print all entries void SplayTreeInventory::printAllHelper(Node* s) { if (s == NULL) { return; } printAllHelper(s->left); cout << s->key << ": " << s->value << endl; printAllHelper(s->right); }

// OUTPUT: prints string representation of all entries in the inventory void SplayTreeInventory::printAll() { printAllHelper(this->stmap->root); }

// OUTPUT: prints string representation of the splay tree representing the inventory void SplayTreeInventory::printTree() { this->stmap->printTree(this->stmap->root, 0); }

// OUTPUT: prints number of entries in the inventory void SplayTreeInventory::printSize() { cout << this->size() << endl; }

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!