Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ please quickly Implement the following StoreShelf as described below: Each StoreShelf contains a number of items; Implement class StoreShelf with the following: Three private
C++ please quickly
Implement the following StoreShelf as described below:
Each StoreShelf contains a number of items; Implement class StoreShelf with the following:
- Three private data member: (6 points)
- int maxSize
- int current to track the current number of food items in the StoreShelf. This attribute gets modified whenever an item is inserted or removed from list.
- string *list a pointer a dynamic array of strings that represent the food items on the shelf.
- The following public member functions: (54 points)
- StoreShelf(int s): creates an empty StoreShelf and sets maxsize to s. (2 points)
- ~StoreShelf(): Deallocate list. (2 points)
- isEmpty(), a boolean function that returns true if current ==0. and false otherwise. (2 points)
- isFull(), a boolean function that returns true if current == maxSize, and false otherwise. (2 points)
- void grow() to expand the dynamic array. The dynamic array size grows by the following (10 points):
- doubling its maxSize.
- Creating a new array with the doubled maxSize
- Copying the contents of the old dynamic array to the new one
- deleting the old array
- int find(string item) returns the index of item if found in list, otherwise returns -1. HINT: use string compare function from the string library.(5 points)
- void insert(string item):this function does the following:(8 points)
- i. Inserts item into the end of list StoreShelf, if the StoreShelf is not full and item does not exist in list.
- ii. If item to be inserted is already in list, then print a message saying the item wont be inserted because it already exists in list.
- iii. If item is not in list, but list is full, then grow the list, then add the item to the end of list. (8 points)
/*hint for insert function: make use of the grow and find functions*/
-
- void update(int loc, string Item): update the item in list at loc with the value of Item, only if list is not empty, and if loc is in the rang 0 to current-1 inclusive. (3 points)
- void printStoreShelf(): prints the items currently in the StoreShelf alongside their number. (3 points)
- Setter and getter for maxSize and getter for current . (5 points)
- float utilization() that calculates the percentage of used food items in a StoreShelf. (3 points)(hint: utilization is 100*current/maxSize) //we need the division to be a floating-point division
- Friend function called remove(StoreShelf st). It removes the first item from list and shifts remaining items, only if list is not empty (5 points)
- Make all the functions that do not change the values of the attributes constant. (4 points)
Write a driver program to test the class you have implemented:
- Create an array of strings objects named myfood_items of size 5 and fill it from the user. ( 5 points)
- Create a StoreShelf object named shelf with maxsize 10 and fill it using the food items from myfood_items array. ( 10 points)
- Add 10 new items to shelf with values entered from the user. ( 5 points)
- Update the kth item in shelf with value entered from the user, where k is also provided by the user. ( 5 points)
- Remove the first 4 items from the list in shelf. ( 5 points)
- Print the utilization of the StoreShelf to the screen. ( 5 points)
- Display the details of the StoreShelf. ( 5 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started