Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background This lab helps you learn inheritance and polymorphism. The classes and functionality are minimal, but they make you exercise the main features of inheritance

Background

This lab helps you learn inheritance and polymorphism. The classes and functionality are minimal, but they make you exercise the main features of inheritance and polymorphism. To make sure you do the critical themes, there are places where you must implement it a certain way.

Specification

You have started a small bakery business called Bread and Cakes. This piece of software allows customers to make an on-line order. The customer first enters the specific baked goods to order (with a quantity) and you create an object for each individual good that they have ordered. You then confirm by printing the created objects. Lastly, you print an invoice of the order with final pricing, including discounts.

Your bakery offers loaves of bread, layer-cakes, and cupcakes. You need to create an inheritance hierarchy for these. You will create 5 classes named as follows. Start with a base class called BakedGood which must be an abstract class (i.e. it contains at least one pure virtual function). There are two classes which derive from BakedGood. One is the Bread class and the other is another abstact class called Cake, from which LayerCake and CupCake are derived. Shared members should be declared in the most base class possible. Your base classes may have their data members as protected rather than private if you prefer, allowing the derived classes to directly access the data members of base classes. Your three derived classes Bread, LayerCake and CupCake should at least each have the following virtual member functions (you can name them what you want):

ToString: Returns a string containing the basic description and base price of the object. While there are only three broad classes of objects (Bread, LayerCake, CupCake), there are lots of different variations of baked goods (white bread, wheat bread, 3-layer spice cupcake with vanilla frosting, Chocolate cupcake with cream-cheese frosting and red sprinkles, etc.) You do NOT have a class for each baked good, just for the three broad classes.

DiscountedPrice: Takes as parameter the total number of a particular baked good and returns the discounted total price for that baked good.

Part 1 - Enter the bakery order and create class objects

Prompt the user to enter sub-orders. Enter "done" to finish. Each order specifies a baked good and begins with either "Bread", "Layer-cake", or "Cupcake", followed by options and quantity (see sample I/O for details). You may assume that the user inputs correct values. You are not required to error check.

Your breads can be any variety (white, wheat, rye. etc) as the bread variety is just a string in the object.

LayerCakes and CupCakes have a flavor (e.g. chocolate, yellow, spice) and a frosting (e.g. chocolate, vanilla, cream-cheese)

LayerCakes have a number of layers

CupCakes have a sprinkles color

Store each object as a pointer in a one polymorphic vector of pointers. Keep them in the same order as entered. Later orders are added to the end of the current list.

The object is not a sub-order but rather a single baked good. Thus, if a person orders 4 loaves of Wheat bread, as in the example below, you create four Bread objects of variety "Wheat", pushing each pointer separately into your vector.

Each object must have a base price computed in its constructor. Base pricing is as follows:

image text in transcribed

Part 2 - Confirm proper class creation by printing your vector with ToString (65 points)

Loop through the object pointer vector and print each description using the virtual ToString member function for each object. The ToString function prints a description of the object followed by its non-discounted base price (see sample I/O). The base price part of the returned ToString string is the same for the classes Bread, CupCake and LayerCake, so that part must be done in the BakedGood class. The rest of the string is generated by the ToString function of the current object class. Thus, for a wheat bread description, the "Wheat Bread" part of the string is generated by the ToString virtual function in Bread which calls the ToString virtual function in BakedGood to get the cost part " ($4.50)". TAs will check your code to make sure you have properly created classes and used polymorphism as described in the specification.

Part 3 - Print an Invoice (35 points)

Print an invoice of the order listing each unique baked good with description (includes base price), quantity, and total discounted price on a row. Summed totals appear on the last row. White space checking is off, but for your information our setwidth values are 75 for the baked good column and 9 for the other columns. Each baked good's discounted price must be calculated by a virtual function implemented in the corresponding class. The magic numbers from the following table must only be found in these function implementations and declared as constants.

image text in transcribed

Thus, if one ordered 2 loaves of the same variety bread the cost is $9.00. 3 loaves would still be $9.00, and 4 would be $13.50. If one ordered 4 2-layer chocolate cakes with vanilla frosting, they would cost $10.00 each. If one ordered 2 3-layer spice cakes with cream-cheese frosting there would be no discount.

Note that there is a little bit of algorithm to write for the invoice. Your vector just contains a long list of baked goods, some of them being repeats. For example "Wheat bread" occurs 4 times in the example below and "White Bread" occurs twice. Note that the White Bread orders occur at different places in the overall order, as a customer may decide to order more later in the order. When you print your invoice you should just print each unique baked good once on its own line with a count of how many times it occurs. That same count is passed to the DiscountedPrice virtual function which returns the discounted total price for that particular baked good. Note that two baked goods are the same if their ToString values are the same. You can use that to go through the vector and get a count for each type of baked good. The auto-grader assumes baked goods are ordered by when the baked good first appeared in the order.image text in transcribedimage text in transcribed

Deductions graded by TA's

We don't expect you to miss any here as these just describe more carefully the specs and learning goals of the lab. Read them carefully, as you don't want to have a working program which gets 0 points!

Adherence to the style guidelines. Pay particular attention to the Objects and Classes section. (up to 20 points)

Use inheritance and polymorphism to solve this lab. (30 points)

Shared data members and member functions should always be declared in the most base class possible. (5 point deduction each case)

You must create the class declarations and definitions in separate files. (15 points)

The BakedGood class and the Cake class must be abstract classes. (5 points each)

Create virtual member functions to get discounted prices for appropriate classes. (5 point deduction in each case)

Create virtual ToString member functions (call them what you want) for appropriate classes. Your ToString member functions must return a string and NOT use a cout. (5 point deduction in each case)

The base price part of any string returned by a ToString function must be created by calling the ToString function of the BakedGood class. (10 points)

Use a single vector of pointers to store all objects. (15 points)

Notes

Member functions can be constant which would look like: int MyFunc() const; and pure virtual which would look like: virtual int AnotherFunc() = 0;. A function that is both constant and pure virtual would look like: virtual int LastFunc() const = 0;.image text in transcribed

Class Price Cream-Cheese Frosting # Layers Bread $4.50 CupCake$1.95 add $.20 LayerCake $9.00 add $1.00 per layer $ 3.00 per layer beyond 1 Class Price Cream-Cheese Frosting # Layers Bread $4.50 CupCake$1.95 add $.20 LayerCake $9.00 add $1.00 per layer $ 3.00 per layer beyond 1

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago