Answered step by step
Verified Expert Solution
Link Copied!

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:

  1. Three private data member: (6 points)
    1. int maxSize
    2. 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.
    3. string *list a pointer a dynamic array of strings that represent the food items on the shelf.

  1. The following public member functions: (54 points)
    1. StoreShelf(int s): creates an empty StoreShelf and sets maxsize to s. (2 points)
    2. ~StoreShelf(): Deallocate list. (2 points)
    3. isEmpty(), a boolean function that returns true if current ==0. and false otherwise. (2 points)
    4. isFull(), a boolean function that returns true if current == maxSize, and false otherwise. (2 points)
    5. void grow() to expand the dynamic array. The dynamic array size grows by the following (10 points):
      1. doubling its maxSize.
      2. Creating a new array with the doubled maxSize
      3. Copying the contents of the old dynamic array to the new one
      4. deleting the old array
    6. 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)
    7. 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*/
 
    1. 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)
    2. void printStoreShelf(): prints the items currently in the StoreShelf alongside their number. (3 points)
    3. Setter and getter for maxSize and getter for current . (5 points)
    4. 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
    5. 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)
  1. 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:

  1. Create an array of strings objects named myfood_items of size 5 and fill it from the user. ( 5 points)
  2. Create a StoreShelf object named shelf with maxsize 10 and fill it using the food items from myfood_items array. ( 10 points)
  3. Add 10 new items to shelf with values entered from the user. ( 5 points)
  4. Update the kth item in shelf with value entered from the user, where k is also provided by the user. ( 5 points)
  5. Remove the first 4 items from the list in shelf. ( 5 points)
  6. Print the utilization of the StoreShelf to the screen. ( 5 points)
  7. Display the details of the StoreShelf. ( 5 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions