C++ Finish the Pizza class declaration by creating mutator and accessor function
ID: 3780020 • Letter: C
Question
C++ Finish the Pizza class declaration by creating mutator and accessor functions for the type of pizza, called pizza Type, and the number of slices, called numSlices. Then create two constructors: the default and overloaded constructor. The default constructor will initialize the type of pizza to "cheese" and the number of slices to 0. The overloaded constructor will take as argument the type of pizza and the number of slices. class Pizza {private://FINISH ME public://FINISH ME with mutator and accessor declarations//FINISH ME WITH constructor declaration};//FINISH ME WITH DEFAULT CONSTRUCTOR//FINISH ME WITH OVERLOADED CONSTRUCTORExplanation / Answer
// Pizza.cpp
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
class Pizza
{
private:
string pizzaType;
int numSlices;
public:
Pizza();
Pizza(string type, int number);
void setpizzaType(string type);
void setnumSlices(int number);
string getpizzaType();
int getnumberSlices();
};
// setpizzaType sets type of ordered pizza
Pizza::Pizza()
{
pizzaType = "cheeze";
numSlices = 0;
}
// setnumSlices sets value of ordered numSlices
Pizza::Pizza(string type, int number)
{
pizzaType = type;
numSlices = number;;
}
// setpizzaType sets type of ordered pizza
void Pizza::setpizzaType(string type)
{
pizzaType = type;
}
// setnumSlices sets value of ordered numSlices
void Pizza::setnumSlices(int number)
{
numSlices = number;
}
// getpizzaType returns type in the member variable pizzaType
string Pizza::getpizzaType()
{
return pizzaType;
}
// getnumberSlices returns value in the member variable numSlices
int Pizza::getnumberSlices()
{
return numSlices;
}
int main()
{
Pizza p; // Instance of pizza class object
cout << "Default type: " << p.getpizzaType() << endl;
cout << "Default slices: " << p.getnumberSlices() << endl;
Pizza p1("Olive", 5); // Instance of pizza class object
cout << " Parameterized type: " << p1.getpizzaType() << endl;
cout << "Parameterized slices: " << p1.getnumberSlices() << endl;
return 0;
}
/*
output:
Default type: cheeze
Default slices: 0
Parameterized type: Olive
Parameterized slices: 5
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.