C++ Programming Language Assignment --------------------------------------------
ID: 3834488 • Letter: C
Question
C++ Programming Language
Assignment
-----------------------------------------------------
Please help me by fixing my code.
-----------------------------------------------------
This is the original 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".
-----------------------------------------------------
Below is the code I have so far. Please help me fix it.
-----------------------------------------------------
-----------------------------------------------------
// Module: pizzaClass.h
#pragma once
class pizzaClass
{
protected: // protected so the derived class can use these data members
string size;
string shape;
string crustType;
string cheeseType;
int toppings;
public:
void setcrustType(string crust)
{
crustType = crust;
}
string getCrustType()
{
return crustType;
}
void setCheeseType(string cheese)
{
cheeseType = cheese;
}
string getCheeseType()
{
return cheeseType;
}
void setToppings(int number)
{
toppings = number;
}
int getToppings()
{
return toppings;
}
void setSize(string size)
{
this->size = size;
}
void setShape(string shape)
{
this->shape = shape;
}
string getsize()
{
return size;
}
string getShape()
{
return shape;
}
pizzaClass();
~pizzaClass();
};
-----------------------------------------------------
-----------------------------------------------------
// Module: pizzaClass.cpp
#include "stdafx.h" // include standard library
#include <iostream> // include format library
#include <string>
using namespace std; // using standard namespaces
pizzaClass::pizzaClass()
{
}
pizzaClass::~pizzaClass()
{
}
-----------------------------------------------------
-----------------------------------------------------
// Module: desertClass.h
#pragma once
class desertClass :public pizzaClass //inherit pizzaClass
{
private:
string fillingtype;
//desert pie can access the data members and public functions of Pizza class
public:
void setFillingType(string fill)
{
fillingtype = fill;
}
string getFillingType()
{
return fillingtype;
}
desertClass();
~desertClass();
};
-----------------------------------------------------
-----------------------------------------------------
// Module: desertClass.cpp
#include "stdafx.h" // include standard library
#include <iostream> // include format library
#include <iomanip> // include input, output library
#include <string>
using namespace std;
desertClass::desertClass()
{
}
desertClass::~desertClass()
{
}
-----------------------------------------------------
-----------------------------------------------------
// Module: Main.cpp
#include "stdafx.h" // include standard library
#include <iostream> // include format library
#include <iomanip> // include input, output library
#include <string> // include string library
#include "pizzaClass.h" // include pizzaClass header
#include "desertClass.h" // include desertClass header
using namespace std; // using standard namespaces
// main program entry
void main()
{
desertClass desertPie; //creating object for DesertPie CLass
pizzaClass pizzaPie; // Creating Object for Pizza class
// Pizza class is base class and can access only its member function
//through pizza object
pizzaPie.setCheeseType("American Cheese");
pizzaPie.setToppings(5);
pizzaPie.setShape("Round");
pizzaPie.setSize("Big");
pizzaPie.setcrustType("cheese-burst. Crust with oodles of yummy liquid cheese filled inside.");
cout << "The Pizza Cheese Type -->" << pizzaPie.getCheeseType() << endl;
cout << "The pizza's Toppings are -->" << pizzaPie.getToppings() << endl;
cout << "The Pizza's Shape is -->" << pizzaPie.getShape() << endl;
cout << "The Pizza, Size is -->" << pizzaPie.getsize() << endl;
cout << "The pizza crust Type is -->" << pizzaPie.getCrustType() << endl;
/* Since desertPie class inherit the pizza class as Public. So this class can use
its member funcions and data members
*/
desertPie.setCheeseType("Cheddar");
desertPie.setFillingType("fried Potato");
desertPie.setShape("Round");
desertPie.setSize("Small");
desertPie.setToppings(5);
cout << "The desertPie Cheese Type -->" << desertPie.getCheeseType() << endl;
cout << "The desertPie's Toppings are -->" << desertPie.getToppings() << endl;
cout << "The desertPie's Shape is -->" << desertPie.getShape() << endl;
cout << "The desertPie, Size is -->" << desertPie.getsize() << endl;
cout << "The filling type is-->" << desertPie.getFillingType() << endl;
system("Pause"); //Pause the program so that the console does not disappear until a key is pressed.
}
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.
Explanation / Answer
// Module: pizzaClass.h
#include<iostream>
#include<string>
using namespace std;
//Class pizzaClass
class pizzaClass
{
// protected so the derived class can use these data members
protected:
string size;
string shape;
string crustType;
string cheeseType;
int toppings;
public:
//Member functions
//To set crust type
void setcrustType(string crust);
//To return crust type
string getCrustType();
//To set cheese type
void setCheeseType(string cheese);
//To return cheese type
string getCheeseType();
//To set toppings
void setToppings(int number);
//To return toppings
int getToppings();
//To set the pizza size
void setSize(string size);
//To set pizza shape
void setShape(string shape);
//To return pizza size
string getsize();
//To return pizza shape
string getShape();
};//End of class
---------------------------------------------
// Module: pizzaClass.cpp
#include "pizzaClass.h"
#include <iostream> // include format library
#include <string>
using namespace std; // using standard namespaces
//Function to set crustType
void pizzaClass::setcrustType(string crust)
{
crustType = crust;
}//End of function
//Function to return crust type
string pizzaClass::getCrustType()
{
return crustType;
}//End of function
//Function to set cheese type
void pizzaClass::setCheeseType(string cheese)
{
cheeseType = cheese;
}//End of function
//Function to return cheese type
string pizzaClass::getCheeseType()
{
return cheeseType;
}//End of function
//Function to set toppings
void pizzaClass::setToppings(int number)
{
toppings = number;
}//End of function
//Function to return toppings
int pizzaClass::getToppings()
{
return toppings;
}//End of function
//Function to set the pizza size
void pizzaClass::setSize(string size)
{
this->size = size;
}//End of function
//Function to set pizza shape
void pizzaClass::setShape(string shape)
{
this->shape = shape;
}//End of function
//Function to return pizza size
string pizzaClass::getsize()
{
return size;
}//End of function
//Function to return pizza shape
string pizzaClass::getShape()
{
return shape;
}//End of function
---------------------------------------------
// Module: desertClass.h
//Creates a class desertClass derived from pizzaClass
class desertClass : public pizzaClass //inherit pizzaClass
{
private:
string fillingtype;
//desert pie can access the data members and public functions of Pizza class
public:
//To set the filling type
void setFillingType(string fill);
//To return filling type
string getFillingType();
};
------------------------------
// Module: desertClass.cpp
//#include "stdafx.h" // include standard library
#include "desertClass.h"
#include <iostream> // include format library
//#include <iomanip> // include input, output library
#include <string>
using namespace std;
//Function to set the filling type
void desertClass::setFillingType(string fill)
{
fillingtype = fill;
}//End of function
//Function to return filling type
string desertClass::getFillingType()
{
return fillingtype;
}//End of function
--------------------------------------
// Module: Main.cpp
//#include "stdafx.h" // include standard library
#include <iostream> // include format library
#include <iomanip> // include input, output library
#include <string> // include string library
#include "pizzaClass.cpp" // include pizzaClass header
#include "desertClass.cpp" // include desertClass header
using namespace std; // using standard namespaces
// main program entry
int main()
{
desertClass desertPie; //creating object for DesertPie CLass
pizzaClass pizzaPie; // Creating Object for Pizza class
// Pizza class is base class and can access only its member function
//through pizza object
pizzaPie.setCheeseType("American Cheese");
pizzaPie.setToppings(5);
pizzaPie.setShape("Round");
pizzaPie.setSize("Big");
pizzaPie.setcrustType("cheese-burst. Crust with oodles of yummy liquid cheese filled inside.");
cout << "The Pizza Cheese Type -->" << pizzaPie.getCheeseType() << endl;
cout << "The pizza's Toppings are -->" << pizzaPie.getToppings() << endl;
cout << "The Pizza's Shape is -->" << pizzaPie.getShape() << endl;
cout << "The Pizza, Size is -->" << pizzaPie.getsize() << endl;
cout << "The pizza crust Type is -->" << pizzaPie.getCrustType() << endl;
/* Since desertPie class inherit the pizza class as Public. So this class can use
its member funcions and data members
*/
desertPie.setCheeseType("Cheddar");
desertPie.setFillingType("fried Potato");
desertPie.setShape("Round");
desertPie.setSize("Small");
desertPie.setToppings(5);
cout << "The desertPie Cheese Type -->" << desertPie.getCheeseType() << endl;
cout << "The desertPie's Toppings are -->" << desertPie.getToppings() << endl;
cout << "The desertPie's Shape is -->" << desertPie.getShape() << endl;
cout << "The desertPie, Size is -->" << desertPie.getsize() << endl;
cout << "The filling type is-->" << desertPie.getFillingType() << endl;
}//End of main
Output:
The Pizza Cheese Type -->American Cheese
The pizza's Toppings are -->5
The Pizza's Shape is -->Round
The Pizza, Size is -->Big
The pizza crust Type is -->cheese-burst. Crust with oodles of yummy liquid cheese filled inside.
The desertPie Cheese Type -->Cheddar
The desertPie's Toppings are -->5
The desertPie's Shape is -->Round
The desertPie, Size is -->Small
The filling type is-->fried Potato
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.