ntory program COMMAND MENU add- add items to wizard_all_items.txt walk - Walk down the p
Wizard Program C++
Console
The Wizard Inventory program
COMMAND MENU
add- add items to wizard_all_items.txt
walk - Walk down the path
show - Show all items from text file wizard_all_items.txt
search - search for items from wizard_all_items.txt
drop - Drop an item
exit - Exit program
command: add
Walking down a path, you see a rock.
Do you want to add it to inventory? y/n:y
Rock is now added to inventory
Command: search
You are searching your bag for a water bottle.
If found return you pull your water bottle out, if not found say "water bottle is not in inventory, keep walking down path to add it to your inventory"
Command: walk
While walking down a path, you see a crossbow.
Do you want to grab it? (y/n): y
You picked up a crossbow.
Command: show
1. a crossbow
Command: drop
Number: -1
Invalid item number.
Command:
The error message if the program can’t find the items file
Could not find file: wizard_all_items.txt
Exiting program. Bye!
Specifications
- The file named wizard_all_items.txt is attached and contains a list of all possible items that a wizard can carry. When the user selects the walk command, read these items from the file, randomly pick one, and give the user the option to grab it.
- User should be able to add items to wizard_all_items to have in inventory
- User should be able to search text file wizard_all_items for items
- The current items that the wizard is carrying should be stored in wizard_inventory.txt. Make sure it updates this file every time the user grabs or drops an item.
- The program should use a function to read the list of items and the wizard’s inventory from a file. If this function can’t find the file, it should throw an exception. Then, the calling code should catch and handle this exception in an appropriate way.
- If the items file is missing, display an appropriate error message and exit the program. Comments are provided on lines 46,48,51 and 53 to indicate where the exceptions should be handled.
- If the inventory file is missing, display an appropriate error message and continue with an empty inventory for the user. That way, the program will create a new inventory file when the user adds items to the inventory.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images