Question

**CODE in C++ **Include the UML and Class activity diagram. ABC pies sells two types of pies (pum...

**CODE in C++

**Include the UML and Class activity diagram.

ABC pies sells two types of pies (pumpkin and pecan ) and allows customers to order a specific number of pies. When an order is made, the overall price is calculated based on the type of pie.

If a pecan pie order is made, you get a discount of half off from the total price if the season fall or winter. If the season is summer , $2.50 should be added to the total price to account for extra labor.

If a pumpkin pie order is made, you get a discount of half off if you have an extra flavor of chocolate or caramel. If you have an extra flavor of vanilla and the number of orders is greater than or equal to 5, $20.99 should be added to the total order price.

1.Create an abstract base class called Pie.

2.Create additional classes that would be used in solving the above scenario. They should inherit the constructor from the base class and implement a pure virtual function that calculates the total cost. Nothing else should be present in these derived classes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ program to create an abstract base class Pie and derived classes PecanPie and PumpkinPie

#include <iostream>

#include <iomanip>

using namespace std;

// abstract class Pie

class Pie

{

       int quantity;

public:

       const static double price = 5.00; // setting a constant price for a pie

       Pie(int quantity);

       virtual double totalCost()=0; // pure virtual function

       int getQuantity() const;

};

Pie::Pie(int quantity) : quantity(quantity)

{}

int Pie::getQuantity() const

{

       return quantity;

}

// derived class PecanPie

class PecanPie : public Pie

{

       string season;

public:

       PecanPie(int quantity, string season);

       double totalCost();

};

PecanPie::PecanPie(int quantity, string season) : Pie(quantity) , season(season)

{}

double PecanPie::totalCost()

{

       double cost = getQuantity()*price;

       if((season.compare("fall") == 0) || (season.compare("winter") == 0))

             cost = cost/2;

       else if(season.compare("summer") == 0)

             cost += 2.5;

       return cost;

}

// derived class PumpkinPie

class PumpkinPie: public Pie

{

       string flavor;

public:

       PumpkinPie(int quantity, string flavor);

       double totalCost();

};

PumpkinPie::PumpkinPie(int quantity, string flavor) : Pie(quantity) , flavor(flavor)

{}

double PumpkinPie::totalCost()

{

       double cost = getQuantity()*price;

       if((flavor.compare("chocolate") == 0) || (flavor.compare("caramel") == 0))

             cost = cost/2;

       else if((flavor.compare("vanilla") == 0 ) && (getQuantity() >= 5))

             cost += 20.99;

       return cost;

}

int main() {

       //test the classes

       PecanPie pie1(10,"summer"), pie2(5,"fall"), pie3(7,"winter"), pie4(12,"spring");

       PumpkinPie pPie1(10,"chocolate"), pPie2(5,"caramel"), pPie3(4,"vanilla"), pPie4(7,"vanilla"), pPie5(10,"mango");

       cout<<"Pecan Pie 1 cost : $"<<fixed<<setprecision(2)<<pie1.totalCost()<<endl;

       cout<<"Pecan Pie 2 cost : $"<<fixed<<setprecision(2)<<pie2.totalCost()<<endl;

       cout<<"Pecan Pie 3 cost : $"<<fixed<<setprecision(2)<<pie3.totalCost()<<endl;

       cout<<"Pecan Pie 4 cost : $"<<fixed<<setprecision(2)<<pie4.totalCost()<<endl;

       cout<<"Pumpkin Pie 1 cost : $"<<fixed<<setprecision(2)<<pPie1.totalCost()<<endl;

       cout<<"Pumpkin Pie 2 cost : $"<<fixed<<setprecision(2)<<pPie2.totalCost()<<endl;

       cout<<"Pumpkin Pie 3 cost : $"<<fixed<<setprecision(2)<<pPie3.totalCost()<<endl;

       cout<<"Pumpkin Pie 4 cost : $"<<fixed<<setprecision(2)<<pPie4.totalCost()<<endl;

       cout<<"Pumpkin Pie 5 cost : $"<<fixed<<setprecision(2)<<pPie5.totalCost()<<endl;

       return 0;

}

//end of program

Output:

Pecan Pie 1 cost $52.50 Pecan Pie 2 cost $12.50 Pecan Pie 3 cost $17.50 Pecan Pie 4 cost $60.00 Pumpkin Pie 1 cost $25.00 Pum

Add a comment
Know the answer?
Add Answer to:
**CODE in C++ **Include the UML and Class activity diagram. ABC pies sells two types of pies (pum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Java) Please include one data type class and one driver class in the program. Please also...

    (Java) Please include one data type class and one driver class in the program. Please also include a UML diagram and pseudocode. B. REQUIREMENT STATEMENT THIS LAB REQUIRES OBJECT ORIENTED PROGRAMMING. YOU HAVE TO CREATE ONE DATA TYPE CLASS AND ONE DRIVER CLASS (include main) One company request an application that allows users to READ from the keyboard the information of a vendor: name (String), id (String), sale amount in the month (double) then calculate the salary of vendors based...

  • UML CLASS DIAGRAM This is a Design Exercise. You will need to make classes that could...

    UML CLASS DIAGRAM This is a Design Exercise. You will need to make classes that could be used to stage a battle as described below. You have been tasked to create a number of items that can be used in an online game. All items can be used on a game character who will have a name, a number of health-points and a bag to hold the items.   Here are examples of items that can be made: Item type of...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Pop’s Pie Shop wants you to help computerize its ever-changing menu. Here’s an example of the...

    Pop’s Pie Shop wants you to help computerize its ever-changing menu. Here’s an example of the delicious items that Pop’s has to offer: Here is what we are starting with today: Savory: Savory Mince & Cheese Pork & Peach BBQ C urried Lamb & Spinach Chicken & Kumara Smoked Salmon, Leek & Potato Thai Butternut Curry (vegan) Sausage Roll Spinach & Cheese Roll Beef Pasty Sweet Pie by the slice: Banoffee Blueberry Apple (vegan) Buttermilk & Raspberry Chocolate Chess Chocolate...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

  • In Java plz due today Assignment 4 - Email, Shwitter and Inheritance Select one option from...

    In Java plz due today Assignment 4 - Email, Shwitter and Inheritance Select one option from below. All (both) options are worth the same number of points. The more advanced option(s) are provided for students who find the basic one too easy and want more of a challenge. OPTION A (Basic): Message, EMail and Tweet Understand the Classes and Problem Every message contains some content ("The British are coming! The British are coming!"). We could enhance this by adding other...

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • ​I have to create two classes one class that accepts an object, stores the object in...

    ​I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList {    private ShoppingItem [] list;    private int amtItems = 0;       public ShoppingList()    {       list=new ShoppingItem[8];    }       public void add(ShoppingItem item)    {       if(amtItems<8)       {          list[amtItems] = ShoppingItem(item);...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue....

    Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ.   Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT