Question
This program will allow the user to specify gift items a create a gift basket by adding and deleting gift items. (1) Prompt the user
This program will allow the user to specify gift items a create a gift basket by adding and deleting gift items.
(1) Prompt the user to input a positive number - the number of gift items - must be positive or print error and re-enter.
Input number of gift items: -2 ERROR: number of items must be greater than zero. Input number of gift items: 0 ERROR: number of items must be greater than zero. Input number of gift items: 3
(2) Create an array of gift item names and an array of gift item quantities. (3) Ask the user to input the name of each gift item and store into an array.
Input name of gift item 1: ham Input name of gift item 2: egg Input name of gift item 3: cheese
(4) Display a menu as in the following:
--------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit ---------------------
NOTE: you are adding one to a particular gift item quantity, or deleting one from a gift item quantity. (5) Prompt and read a command from the user, and perform the action.
Please enter command:
(6) Show basket will list all gift item names and its quantity - see example below
Please enter command: s 1) ham: 0 2) egg: 0 3) cheese: 0
(7) Add a gift item will add 1 to the quantity of a particular gift item. It will ask the user to input gift item name and add 1 to the corresponding gift item quantity; if not found, print error. Tell user that item added if success.
Please enter command: a Input gift item name: ham Item added.
Please enter command: a Input gift item name: fruit ERROR: fruit not found.
(8) Delete a gift item will ask the user to input gift item name and delete 1 from the corresponding gift item quantity; if less than zero, set to zero; if not found, print error. Tell user that item deleted if success.
Please enter command: d Input gift item name: ham Item deleted.
Please enter command: d Input gift item name: fruit ERROR: fruit not found.
(9) Empty basket will set all gift item quantities to zero. Tell use that basket is emptied.
Please enter command: e Basket emptied.
(10) Quit will tell the user that the program is terminated.
Please enter command: q Program terminated.
(11) If command is not valid, print error.
Please enter command: k ERROR: Invalid command.
Complete example:
Input number of gift items: -2 ERROR: number of items must be greater than zero. Input number of gift items: 0 ERROR: number of items must be greater than zero. Input number of gift items: 3 Input name of gift item 1: ham Input name of gift item 2: egg Input name of gift item 3: cheese --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: a Input gift item name: ham Item added. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: a Input gift item name: ham Item added. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: a Input gift item name: ham Item added. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: a Input gift item name: cheese Item added. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: a Input gift item name: fruit ERROR: fruit not found. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: s 1) ham: 3 2) egg: 0 3) cheese: 1 --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: d Input gift item name: ham Item deleted. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: d Input gift item name: egg Item deleted. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: d Input gift item name: fruit ERROR: fruit not found. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: s 1) ham: 2 2) egg: 0 3) cheese: 1 --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: e Basket emptied. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: s 1) ham: 0 2) egg: 0 3) cheese: 0 --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: k ERROR: Invalid command. --------------------- MENU --------------------- (A)dd a gift item (D)elete a gift item (E)mpty basket (S)how basket (Q)uit --------------------- Please enter command: q Program terminated.
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