Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Langauge C++ Assignment Inheritance Create a project that contains a

ID: 3829306 • Letter: P

Question

Programming Langauge C++

Assignment

Inheritance

Create a project that contains a base class and a class derived from the base class. Purpose Learn how to create a base class.

Learn how to create a derived class.

Create an object that accesses both the base and the derived class.

Pass data to, and retrieve data from, both the base and derived objects. Instructions . Read the problem.

Create a program that sets the size and shape of a pie. The program should support pizza and desert pies. It should set the crust type, cheese type, and toppings 1, 2, and 3 for pizza pies, and the filling type for desert pies. The program should display the values set for each pie on the console.
2. Object oriented design.

3. Write the program.

Write code that solves the problem described in item 1.

Pause the program so that the console does not disappear until a key is pressed.
4. Insure that you properly document your code.

Explanation / Answer

#include<string>
#include<iostream>

using namespace std;
//base class
class Pie
{
public:
   string shape;
   string size;
};

//child class extends Pie
class PizzaPie :Pie
{
public:
   PizzaPie(string sh, string si, string cr, string ch, string t1, string t2,string t3)
   {

       shape = sh;
       size = si;
       crust = cr;
       cheese = ch;
       topping1 = t1;
       topping2 = t2;
       topping3 = t3;

   }
   void display()
   {
       cout<< shape<<" "<<size<<" "crust << " "<< cheese << " " <<topping1 << " " <<topping2 << " " <<topping3<<endl;
  
   }

   string crust;
   string cheese;
   string topping1;
   string topping2;
   string topping3;
};

//child class extends Pie

class DesertPie : Pie
{
public:
   DesertPie(string sh, string si,string fi )
   {
       shape = sh;
       size = si;
       filling = fi;
   }
   string filling;
   void display()
   {
       cout << shape << " " << size << " " << filling<<endl;
   }
};


int main()
{
DesertPie p1("square","large","cream");
   PizzaPie p2("circle", "medium", "thin", "pamesan", "mozarella", "olive", "sauce");
   p1.display();
   p2.display();
   system("pause");
}