Question

Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. **
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*C++ program that demonstrates the classes CupCake, ChocolateCupCake and WatermelonCupCakeand display the results on the console window.*/
//main.cpp
#include<iostream>
using namespace std;
//Base class CupCake
class CupCake
{
private:
   //private instance variables
   int egg;
   int butter;
   int bakingpowder;
   int sugar;
   int flour;
   int milk;
public:
   /*Default constructor*/
   CupCake()
   {
       egg=0;
       butter=0;
       bakingpowder=0;
       sugar=0;
       flour=0;
       milk=0;
   }
   /*Parameterized constructor*/
   CupCake(int egg, int butter, int bakingpower,
       int sugar, int flour, int milk)
   {
       this->egg=egg;
       this->butter=butter;
       this->bakingpowder=bakingpower;
       this->sugar=sugar;
       this->flour=flour;
       this->milk=milk;
   }
   //pure virtual function
   virtual void showIngredients()=0;
   void setegg(int egg)
   {
       this->egg=egg;
   }
   int getegg()
   {
       return egg;
   }

   void setbutter(int butter)
   {
       this->butter=butter;
   }
   int getbutter()
   {
       return butter;
   }

   void setbakingpowder(int bakingpowder)
   {
       this->bakingpowder=bakingpowder;
   }
   int getbakingpowder()
   {
       return bakingpowder;
   }

   void setsugar(int sugar)
   {
       this->sugar=sugar;
   }
   int getsugar()
   {
       return sugar;
   }

   void setflour(int flour)
   {
       this->flour=flour;
   }
   int getflour()
   {
       return flour;
   }

   void setmilk(int milk)
   {
       this->milk=milk;
   }
   int getmilk()
   {
       return milk;
   }
};

//ChocolateCupCake class that inherits from CupCake class
class ChocolateCupCake : public CupCake
{
private:
   int chocolate;
public:
   /*Constructor that takes values and pass the values to the CupCake constructor*/
   ChocolateCupCake(int egg, int butter, int bakingpower,
       int sugar, int flour, int milk, int chocolate) : CupCake(egg, butter, bakingpower,
       sugar, flour, milk)
   {
       //set the chocolate
       this->chocolate=chocolate;
   }
   /*Override the virtual function, showIngredients*/
   void showIngredients()
   {
       cout<<"Chocolate Cup Cake Ingredients "<<endl;
       cout<<"======================"<<endl;
       cout<<"# of eggs : "<<getegg()<<endl;
       cout<<"Butter(gms) : "<<getbutter()<<endl;
       cout<<"Baking powder(gms) : "<<getbakingpowder()<<endl;
       cout<<"Sugar(kgs) : "<<getsugar()<<endl;
       cout<<"Flour(kgs) : "<<getflour()<<endl;
       cout<<"milk(liter ) : "<<getmilk()<<endl;
       cout<<"# of Chocolate : "<<chocolate<<endl;
       cout<<"======================"<<endl;
   }//end of the method
};

//WatermelonCupCake class that inherits from CupCake class
class WatermelonCupCake : public CupCake
{
private:
   int watermelon;
public:
   /*Constructor that takes values and pass the values to the CupCake constructor*/
   WatermelonCupCake(int egg, int butter, int bakingpower,
       int sugar, int flour, int milk, int watermelon) : CupCake(egg, butter, bakingpower,
       sugar, flour, milk)
   {
       //set the watermelon
       this->watermelon=watermelon;
   }
   /*Override the virtual function, showIngredients*/
   void showIngredients()
   {
       cout<<"Watermelon Cup Cake Ingredients "<<endl;
       cout<<"======================"<<endl;
       cout<<"# of eggs : "<<getegg()<<endl;
       cout<<"Butter(gms) : "<<getbutter()<<endl;
       cout<<"Baking powder(gms) : "<<getbakingpowder()<<endl;
       cout<<"Sugar(kgs) : "<<getsugar()<<endl;
       cout<<"Flour(kgs) : "<<getflour()<<endl;
       cout<<"milk(liter ) : "<<getmilk()<<endl;
       cout<<"# of Watermelon: "<<watermelon<<endl;
       cout<<"======================"<<endl;
   }//end of the method
};

/*Start of the main function*/
int main()
{
   /*Create an object of the class, ChocolateCupCake*/
   ChocolateCupCake chocolatecake(10, 200, 100,1, 2, 1, 10) ;
   //call method, showIngredients
   chocolatecake.showIngredients();

   /*Create an object of the class, WatermelonCupCake*/
   WatermelonCupCake watermeoncake(10, 200, 100,1, 2, 1, 2) ;
   //call method, showIngredients
   watermeoncake.showIngredients();

   system("pause");
   return 0;
}

----------------------------------------Sample Run #---------------------------------------------------

Chocolate Cup Cake Ingredients # of eggs : 10 Butter (gms) : 200 Baking powder (gms) : 100 Sugar (kg) : 1 Flour (kgs) : 2 mil

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

    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. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....

  • 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)...

  • 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...

  • College of Winston and Charlotte This program will calculate the amount for a semester bill at...

    College of Winston and Charlotte This program will calculate the amount for a semester bill at The College of Winston and Charlotte. Part 1: Create a class Course.java: The class has non-static instance variables: private String department private int courseNumber private int courseCredits private double courseCost The class must have a default constructor which will set values as follows: department = “unknown” courseNumber = 0 courseCost = 0 courseCredits = 0 The class must have a non-default constructor which will...

  • 1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When...

    1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When you look at a constructor, how can you determine if it is THE default constructor? 3. What can a “friend” function do that other non-member functions can not do? 4. class plane { int x;} ---------------- is x public or private? 5. What kind of a search first sorts the data into ascending or descending order, then splits the data in half, searches, splits,...

  • 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...

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. 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...

  • 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 ();...

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