Question

Help with this coding assignment for C++! Add any comments for better understanding.

Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flo

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

#include <iostream>
using namespace std;

class CupCake // base class
{
   private:
   int eggs;
   double butter,bakingPowder,sugar,flour, milk;
  
   public:
   //set and get methods
   void setEggs(int eggs)
   {
       this->eggs = eggs;
   }
   int getEggs()
   {
       return eggs;
   }
   void setButter(double butter)
   {
       this->butter = butter;
   }
   double getButter()
   {
       return butter;
   }
   void setBakingPowder(double bakingPowder)
   {
       this->bakingPowder = bakingPowder;
   }
   double getBakingPowder()
   {
       return bakingPowder;
   }
   void setSugar(double sugar)
   {
       this->sugar = sugar;
   }
   double getSugar()
   {
       return sugar;
   }
   void setFlour(double flour)
   {
       this->flour = flour;
   }
   double getFlour()
   {
       return flour;
   }
   void setMilk(double milk)
   {
       this->milk = milk;
   }
   double getMilk()
   {
       return milk;
   }
   CupCake() // default constructor
   {
       eggs = 0;
       butter = 0.0;
       bakingPowder = 0.0;
       sugar = 0.0;
       flour = 0.0;
       milk = 0.0;
   }
  
   virtual void showIngredients() = 0; // pure viirtual function
  
};

//derived classes
class ChocolateCupCake : public CupCake
{
   private:
   double chocolate;
  
   public:
   ChocolateCupCake(double chocolate)
   {
       this->chocolate = chocolate;
   }
   void showIngredients()
   {
       cout<<"\nChocolate Cup Cake Ingredients : ";
       cout<<"\neggs : "<<getEggs();
       cout<<"\nbutter : "<<getBakingPowder();
       cout<<"\nsugar : "<<getSugar();
       cout<<"\nflour : "<<getFlour();
       cout<<"\nmilk : "<<getMilk();
       cout<<"\nchocolate : "<<chocolate;
   }
   void setChocolate(double chocolate)
   {
       this->chocolate = chocolate;
   }
   double getChocolate()
   {
       return chocolate;
   }
  
};

class WatermelonCupCake : public CupCake
{
   private:
   double watermelon;
  
   public:
   WatermelonCupCake(double watermelon)
   {
       this->watermelon = watermelon;
   }
   void showIngredients()
   {
       cout<<"\nWatermelon Cup Cake Ingredients : ";
       cout<<"\neggs : "<<getEggs();
       cout<<"\nbutter : "<<getBakingPowder();
       cout<<"\nsugar : "<<getSugar();
       cout<<"\nflour : "<<getFlour();
       cout<<"\nmilk : "<<getMilk();
       cout<<"\nwatermelon : "<<watermelon;
   }
   void setWatermelon(double watermelon)
   {
       this->watermelon = watermelon;
   }
   double getWatermelon()
   {
       return watermelon;
   }
  
};
int main() {

ChocolateCupCake ccc(120.00);
ccc.setEggs(4);
ccc.setButter(350.50);
ccc.setBakingPowder(10.55);
ccc.setSugar(250.50);
ccc.setFlour(400.00);
ccc.setMilk(250.00);
  
ccc.showIngredients();
  
WatermelonCupCake wcc(220.50);
wcc.setEggs(3);
wcc.setButter(250.50);
wcc.setBakingPowder(10.55);
wcc.setSugar(150.50);
wcc.setFlour(200.00);
wcc.setMilk(250.00);
  
wcc.showIngredients();
  
  
   return 0;
}

output:

Chocolate Cup Cake Ingredients : 
eggs : 4
butter : 10.55
sugar : 250.5
flour : 400
milk : 250
chocolate : 120
Watermelon Cup Cake Ingredients : 
eggs : 3
butter : 10.55
sugar : 150.5
flour : 200
milk : 250
watermelon : 220.5

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
Help with this coding assignment for C++! Add any comments for better understanding. Create a class...
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
  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class...

    Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class named Building with one public pure virtual function computerEnergyConsumption() that returns a double value of the instance variable which stores the energy consumed by the building. Create the two classes SolarBuilding and WindMill that both publicly inherit from Building. SolarBuilding has an instance variable that stores the energy generated by the solar panels. WindMill has...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the...

    Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees....

    JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...

  • 1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - an int variable named year - a string variable named model - a string variable named purpose 1c Add the following public functions: - Default constructor which sets numeric members to -1 and string members to the empty string - Destructor to print "Removing instance from memory" - A non-default constructor to set the year and...

  • This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and...

    This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and TweetManager. You will load a set of tweets from a local file into a List collection. You will perform some simple queries on this collection. The Tweet and the TweetManager classes must be in separate files and must not be in the Program.cs file. The Tweet Class The Tweet class consist of nine members that include two static ones (the members decorated with the...

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