Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ (Need Help!!) Just complete the code where it says Your code here. You do not need to run it. Thanks * available: Return

In C++ (Need Help!!)

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

*available: Return the number of items in the inventory corresponding to the input string ID, or 0 if the item doesnt exist

into: Add a specified number of items with a specified ID to the inventory.

out: Remove a specified number of items with a specified ID from the inventory. If the item is not found, do nothing. If the number of items removed equals or exceeds the current amount in the inventory, erase the entry.

size: Returns the total number of all items in the inventory (i.e. if there are 50 of item A and 30 of item B in the inventory, this function should return 80). Do not perform any splays.

/* *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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions