Question: in c + + Requirements: 1 . Candy Information: - SweetTooth s candies need to be stored in three magical arrays: - ` int *
in c
Requirements:
Candy Information:
SweetTooths candies need to be stored in three magical arrays:
int candyIDs for unique Candy IDs.
char candyNames for the names of the candies, from "Chocolate Frogs" to
"Rainbow Candy Canes" each name is a string stored in dynamically allocated memory
int quantities for the number of each candy in stock.
float prices for the price of each candy, because even in a magical shop, we need to
keep track of our treasure trove!
Dynamic Candy Array Management:
SweetTooth's shop inventory grows every day, so your arrays must be able to grow and
occasionally shrink as new candies are added and old ones are gobbled up by happy
customers.
Implement a resizeArray function to help SweetTooth expand his candy collection.
When the array is full, double its size! When too many candies are removed, make the array
smaller to save space for new delights.
A Magical Menu:
SweetTooth needs a simple menu to manage his candies. Your program should offer
these magical options:
Add a New Candy: Add a new sweet treat to the inventory.
Remove a Candy by ID: Remove a candy that has either sold out or needs to be
retired.
Update Candy Details: Update the quantity or price of an existing candy perhaps
the price of Dragonfire Jawbreakers has gone up
Display All Candies: Show a list of all candies in the shop, along with their details, so
SweetTooth can see his sugary empire at a glance.
Exit: When you're done, safely close the shop for the night, ensuring all memory is
properly freed after all, we wouldnt want any ghost candies haunting the shop!
Magical Memory Management:
Youll be handling SweetTooths inventory, so make sure you allocate and deallocate
memory properly to avoid any nasty memory leaks. When candies are removed, free up the
space so new goodies can be added later!
When the shop closes ie when the program exits make sure all memory is released
to keep things tidy and avoid a sugar crash!
Advanced Wizardry Optional:
If youre feeling particularly magical, add a feature to search for candies by name using
a string comparison spell, of course
You can also implement a sorting charm to organize the candies by price or quantity,
helping SweetTooth keep track of his bestsellers.
Implementation Tips:
Start Small: Begin by implementing the basicsdefine your arrays and get comfortable
with adding and removing items before worrying about resizing.
Pointer Magic: Remember, when dealing with dynamic memory, pointers are your best
friends. Use them wisely to navigate your arrays and manage memory.
Resize with Care: When resizing, make sure to carefully copy over the old candy data to
your new, bigger array. Its like moving to a bigger candy jar!
Check Your Work: After implementing each feature, test it thoroughly. Nothings worse
than finding out your Chocolate Frog count is off by one because of a bug!
Memory Matters: Keep an eye on your memory allocations and deallocations.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
