Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the class hierarchy on the last page of this assignment. It is a class hierarchy of food products, including FreshVegetable and CannedItem. A Package

Consider the class hierarchy on the last page of this assignment. It is a class hierarchy of food products, including FreshVegetable and CannedItem.

A Package is also a product and is a container of multiple products.

We wish to use the visitor pattern to implement two operations on 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 and FreshVegetable items in a product by specified amounts.

We implement this using the ReducePriceVisitor.

You are provided with the main program main.cpp and the completed header file for the Product hierarchy.

Note that the Package is implemented using the vector class from the c++ stl library.

The ProductVisitor hierarchy is partially implemented in ProductVisitor.h.

You need to complete the implementation of the CheapestVisitor and ReducePriceVisitor classes.

You are also required to implement the following methods in the file 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 of the cheapest item

6. Item *CheapestVisitor::getMinItem() // return a pointer to the cheapest item

7. void CheapestVisitor::reset() // reset the CheapestVisitor before finding another cheapest item

All points where implementation is required are marked by the comment TO BE COMPLETED

Compile the code using cc -o product.exe main.cpp ProductVisitor.cpp

There are two test functions in main.cpp - change main() to try each one.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

Students also viewed these Databases questions