Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a c++ code Question 1: Implement the following StoreShelf as described below: Each StoreShelf contains a number of items; Implement class StoreShelf with the

write a c++ code

Question 1: Implement the following StoreShelf as described below:

Each StoreShelf contains a number of items; Implement class StoreShelf with the following: 1. Three private data member: (6 points) a. int maxSize b. 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. c. string *list a pointer a dynamic array of strings that represent the food items on the shelf.

2. The following public member functions: (54 points) a. StoreShelf(int s): creates an empty StoreShelf and sets maxsize to s. (2 points) b. ~StoreShelf(): Deallocate list. (2 points) c. isEmpty(), a boolean function that returns true if current ==0. and false otherwise. (2 points) d. isFull(), a boolean function that returns true if current == maxSize, and false otherwise. (2 points) e. void grow() to expand the dynamic array. The dynamic array size grows by the following (10 points): i. doubling its maxSize. ii. Creating a new array with the doubled maxSize iii. Copying the contents of the old dynamic array to the new one iv. deleting the old array f. 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) g. 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/

h. 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) i. void printStoreShelf(): prints the items currently in the StoreShelf alongside their number. (3 points) j. Setter and getter for maxSize and getter for current . (5 points) k. 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 l. 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)

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

More Books

Students also viewed these Databases questions

Question

Evaluate 3x - 1 / x - 1. lim

Answered: 1 week ago

Question

=+2. What significant opposition exists?

Answered: 1 week ago

Question

very hard question

Answered: 1 week ago