homework assistance wanted: using a class as a vector
I'm trying to create a pizza ordering system that consists of 2 classes. The first one contains all the information for a pizza, while the second consists of an order system for multiple pizzas. For the second one, class order, I am supposed to have a private vector of type pizza. And in this is where I am confused. I am unsure as how to actually use the vector as a class. Here is what I have so far.
Code:
#include <iostream>
#include <vector>
using namespace std;
class pizza
{
private:
int crust;
int size;
int cheese;
int pepperoni;
public:
int getCrust();
void setCrust(int newCrust);
int getSize();
void setSize(int newSize);
int getPepperoni();
void setPepperoni(int newPepperoni);
int getCheese();
void setCheese(int newCheese);
void outputDescription();
double computePrice();
void takeOrder();
};
class order
{
private:
vector<pizza> customer;
public:
void customerOrder();
void customerTotal();
};
int main ()
{
order test;
test.customerOrder();
test.customerTotal();
}
int pizza::getCrust()
{
return crust;
}
int pizza::getSize()
{
return size;
}
int pizza::getPepperoni()
{
return pepperoni;
}
int pizza::getCheese()
{
return cheese;
}
void pizza::setCrust(int newCrust)
{
crust = newCrust;
}
void pizza::setSize(int newSize)
{
size = newSize;
}
void pizza::setCheese(int newCheese)
{
cheese = newCheese;
}
void pizza::setPepperoni(int newPepperoni)
{
pepperoni = newPepperoni;
}
void pizza::outputDescription()
{
cout << "\nThe pizza you ordered is a ";
if(size == 1)
cout << "small ";
else if(size == 2)
cout << "medium ";
else if(size == 3)
cout << "large ";
if(crust == 1)
cout << "deep dish ";
else if(crust ==2)
cout << "hand tossed ";
else if(crust ==3)
cout << "pan ";
cout << "\nwith";
if(cheese == 0 && pepperoni ==0)
cout << " plain cheese.";
else if(cheese == 1 && pepperoni == 0)
cout << " extra cheese.";
else if(cheese == 1 && pepperoni == 1)
cout << " extra cheese and pepperoni.";
else if(cheese == 0 && pepperoni == 1)
cout << " pepperoni.";
else if(cheese == 0 && pepperoni == 2)
cout << " double pepperoni.";
else if(cheese == 1&& pepperoni == 2)
cout << " extra cheese and double pepperoni.";
}
double pizza::computePrice()
{
double sizePrice, toppingsPrice = 0;
double toppings = cheese + pepperoni;
if(size == 1)
sizePrice = 10.00;
else if(size == 2)
sizePrice = 14.00;
else if(size == 3)
sizePrice = 17.00;
if(toppings == 0)
toppingsPrice = 0.00;
else if(toppings == 1)
toppingsPrice = 2.00;
else if(toppings == 2)
toppingsPrice = 4.00;
else if(toppings == 3)
toppingsPrice = 6.00;
double finalPrice = sizePrice + toppingsPrice;
cout << "\n\nThe total price of the order is $" << finalPrice << endl;
return finalPrice;
}
void order::customerOrder()
{
int numberOfPizzas = 0;
char morePizzas;
do
{
++numberOfPizzas;
int i, newSize, newCrust = 0;
int newCheese = 0;
int newPepperoni = 0;
char moreToppings, addToppings;
cout << "What size of pizza would you like? " << endl;
cout << "Type 1 for a small, 2 for a medium, or 3 for a large --> ";
cin >> newSize;
setSize(newSize);
i = 0;
cout << "\nWhat kind of crust would you like? " << endl;
cout << "Type 1 for Deep Dish, 2 for Hand Tossed, or 3 for Pan --> ";
cin >> newCrust;
setCrust(newCrust);
cout << "\nAll pizzas come plain with cheese ";
cout << "do you wish to add extra cheese or pepperoni? ";
cout << "Type 'Y' to add toppings to your pizza or type no to skip --> ";
cin >> moreToppings;
if(moreToppings == 'Y' || moreToppings == 'y')
{
cout << "All toppings are an extra $2.00 charge.";
cout << " Type 'Y' to add the toppings." << endl;
cout << "Do you want EXTRA cheese? ";
cin >> addToppings;
if(addToppings == 'Y' || addToppings == 'y')
newCheese++;
cout << "Do you want pepperoni? ";
cin >> addToppings;
if(addToppings == 'Y' || addToppings == 'y')
{
newPepperoni++;
cout << "Do you want add double pepperoni? ";
cin >> addToppings;
if(addToppings == 'Y' || addToppings == 'y')
newPepperoni++;
}
}
setCheese(newCheese);
setPepperoni(newPepperoni);
cout << "\nDo you want to add another pizza to your order? Type 'Y' for yes ";
cin >> morePizzas;
}
while(morePizzas == 'Y' || morePizzas == 'y');
}
void pizza::takeOrder()
{
int i, newSize, newCrust = 0;
int newCheese = 0;
int newPepperoni = 0;
char moreToppings, addToppings;
cout << "What size of pizza would you like? " << endl;
cout << "Type 1 for a small, 2 for a medium, or 3 for a large --> ";
cin >> newSize;
setSize(newSize);
i = 0;
cout << "\nWhat kind of crust would you like? " << endl;
cout << "Type 1 for Deep Dish, 2 for Hand Tossed, or 3 for Pan --> ";
cin >> newCrust;
setCrust(newCrust);
cout << "\nAll pizzas come plain with cheese ";
cout << "do you wish to add extra cheese or pepperoni? ";
cout << "Type 'Y' to add toppings to your pizza or type no to skip --> ";
cin >> moreToppings;
if(moreToppings == 'Y' || moreToppings == 'y')
{
cout << "All toppings are an extra $2.00 charge.";
cout << " Type 'Y' to add the toppings." << endl;
cout << "Do you want EXTRA cheese? ";
cin >> addToppings;
if(addToppings == 'Y' || addToppings == 'y')
newCheese++;
cout << "Do you want pepperoni? ";
cin >> addToppings;
if(addToppings == 'Y' || addToppings == 'y')
{
newPepperoni++;
cout << "Do you want add double pepperoni? ";
cin >> addToppings;
if(addToppings == 'Y' || addToppings == 'y')
newPepperoni++;
}
}
setCheese(newCheese);
setPepperoni(newPepperoni);
}
void order::customerTotal()
{
double finalTotal = finalTotal + computePrice();
}
Again, what I am unsure of is how to actually use the vector. I know that I am not actually plugging it in anywhere, but thats what I am trying to figure out how and where to use it. Thanks in advance for any advice.