(Solved) : Consider Class Hierarchy Last Page Assignment Class Hierarchy Food Products Including Fres Q34222187 . . .
Consider the class hierarchy on the last page of thisassignment. It is a class hierarchy of food products, includingFreshVegetable and CannedItem.
A Package is also a product and is a container of multipleproducts.
• We wish to use the visitor pattern to implement two operationson the product hierarchy.
• The first operation is to find the cheapest item in a product,which we implement using the CheapestVisitor.
• The second operation is to reduce the price of CannedItem andFreshVegetable items in a product by specified amounts.
We implement this using the ReducePriceVisitor.
You are provided with the main program main.cpp and thecompleted header file for the Product hierarchy.
Note that the Package is implemented using the vector class fromthe c++ stl library.
The ProductVisitor hierarchy is partially implemented inProductVisitor.h.
You need to complete the implementation of the CheapestVisitorand ReducePriceVisitor classes.
You are also required to implement the following methods in thefile called ProductVisitor.cpp:
1. void ProductVisitor::visit(Package *p)
2. void CheapestVisitor::visit(FreshVegetable *p)
3. void ReducePriceVisitor::visit(FreshVegetable *p)
4. void ReducePriceVisitor::visit(CannedItem *p)
5. double CheapestVisitor::getMinPrice() // return the price ofthe cheapest item
6. Item *CheapestVisitor::getMinItem() // return a pointer tothe cheapest item
7. void CheapestVisitor::reset() // reset the CheapestVisitorbefore finding another cheapest item
• All points where implementation is required are marked by thecomment TO BE COMPLETED
• Compile the code using cc -o product.exe main.cppProductVisitor.cpp
• There are two test functions in main.cpp – change main() totry each one.
Expert Answer
Answer to Consider Class Hierarchy Last Page Assignment Class Hierarchy Food Products Including Fres Q34222187 . . .
OR