Question
In C++ Any comments are greatly appreciated Create a base class call Item and a derived class called Consumable. Create two subclasses of Consumable called
In C++
Any comments are greatly appreciated
Create a base class call Item and a derived class called Consumable. Create two subclasses of Consumable called Juice and Chili. Provide the Item class with 3 private variables called name, weight and value. Provide getter and setter methods for each of these variables. Provide constructors and destructors for each class. Each should display a message notifying the user it has been executed.
In main() Create an array of 10 Item pointers. Use a for loop to assign the first five elements an object from the Juice class. Do the same for the last 5 elements but from the Chili class. Make sure your objects are stored on the heap.
Use the setter methods to set the name of the first and last objects. Dont worry about setting the values for the other objects. Create a global function called crazy() that receives 2 item pointers as parameters. Program this function to swap the names of the two items.
Call the function in main() and pass it the two named objects using pass by pointer. Display the names of the two objects after the swap.
Free up all of the memory that was used by the objects before ending your program.
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