rendered paste body// other #includes may go here
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
enum CrustType {THIN, THICK,TOSSED };
enum SizeType {SMALL, MED, LARGE, SUPER};
// Class declaration - DO NOT MODIFY CODE IN THIS SECTION
class PizzaType
{
public:
PizzaType();
// Accessors (getters)
SizeType getSize() const;
CrustType getCrust() const;
string getSizeAsString() const;
string getCrustAsString() const;
// return size & crust settings, as a string.
int howManyIngredients() const;
float getPrice() const;
void printIngredients(ostream& out) const;
// PRE: out is ready to receive output.
// POST: Prints ingredients (up to 5) to out, 1 per line.
// Modifiers (setters)
void setSize(SizeType Sz);
void setCrust(CrustType Cr);
void setNIngredients(int N);
// N must range from 0 to 5 inclusive. Values outside that range
// are silently ignored (i.e. passing this function a value outside
// of range has no effect).
void setIngredients();
// PRE: NIngredients must be set.
// POST: Prompts user for specified numbers of ingredients (strings)
// prompts to screen, reads from keyboard.
// NOTE: each word counts as a separate item... so entering
// 'extra hot peppers' counts as *3* ingredients. Do something
// like: extra-hot-peppers instead.
private:
SizeType size;
CrustType crust;
int N_Ingredients;
string ingredients[5];
};
// end class declaration
// Your function prototypes go here
class Order
{
public:
void PlaceOrder();
PizzaType Pizzas[10];
double OrderTotal;
int NumPizzas;
private:
};
class Pizzeria
{
public:
void OpenPizzeria();
private:
Order Orders[32000];
int NumOrders;
};
ofstream OutputFile; //global variable to use for the file output
int main()
{
// your code goes here
OutputFile.open("PizzaTotals.txt")
Pizzeria Tonys = Pizzeria();
char Again;
do
{
Tonys.OpenPizzeria();
cout << "Open again? (Y/N): ";
cin >> Again;
} while(tolower(Again) != 'n');
OutputFile.close();
return 0;
}
// your function bodies go here
void Pizzeria::OpenPizzeria()
{
char Choice;
NumOrders = 0;
do
{
do
{
cout << "Main menu:\n\n[P]lace Order\n[C]lose for the day\n\nChoice: ";
cin >> Choice;
if(Choice != 'C' && Choice != 'P')
{
cout << "INVALID CHOICE!\n";
}
} while (Choice != 'C' && Choice != 'P');
switch(Choice)
{
case 'P':
Orders[NumOrders] = Order();
Orders[NumOrders].PlaceOrder();
NumOrders++;
break;
}
} while (Choice != 'C');
int NumPizzas = 0;
double TotalIncome = 0;
for(int i = 0; i < NumOrders; i++)
{
NumPizzas += Orders[i].NumPizzas;
TotalIncome += Orders[i].OrderTotal;
}
cout << "Orders for the day: " << NumOrders << "\n";
OutputFile << "Orders for the day: " << NumOrders << "\n";
cout << "Pizzas Sold: " << NumPizzas << "\n";
OutputFile << "Pizzas Sold: " << NumPizzas << "\n";
cout << "Total Price of All Ordes: " << TotalIncome << "\n";
cout << "-----------------------------------------" << "\n";
OutputFile << "Total Price of All Ordes: " << TotalIncome << "\n";
OutputFile << "--------------------------------------" << "\n";
}
void Order::PlaceOrder()
{
do
{
cout << "How may pizzas would you like? (1 - 10): ";
cin >> NumPizzas;
if(NumPizzas > 10 || NumPizzas < 1)
{
cout<< "Invalid selection. Retry.\n\n";
}
} while(NumPizzas > 10 || NumPizzas < 1);
for(int i = 0; i < NumPizzas; i++)
{
cout << "\nPizza #" << (i + 1) << ":\n\n";
Pizzas[i] = PizzaType();
char Size[10];
char Toppings[5][20];
char Crust[10];
int NumIngredients = 0;
SizeType stSize;
cout << "What size would you like? (Small, Medium, Large, Super): ";
cin >> Size;
Size[1] = tolower(Size[1]);
switch(Size[1])
{
case 'm':
Pizzas[i].setSize(SizeType::SMALL);
break;
case 'e':
Pizzas[i].setSize(SizeType::MED);
break;
case 'a':
Pizzas[i].setSize(SizeType::LARGE);
break;
case 'u':
Pizzas[i].setSize(SizeType::SUPER);
break;
}
cout << "What kind of crust would you like? (Thin, Thick, Tossed): ";
cin >> Crust;
Crust[3] = tolower(Crust[3]);
switch(Crust[3])
{
case 'n':
Pizzas[i].setCrust(CrustType::THIN);
break;
case 'c':
Pizzas[i].setCrust(CrustType::THICK);
break;
case 's':
Pizzas[i].setCrust(CrustType::TOSSED);
break;
}
cout << "How many ingredients would you like? (1-5): ";
cin >> NumIngredients;
Pizzas[i].setNIngredients(NumIngredients);
Pizzas[i].setIngredients();
}
cout << "\n\nOrder Summary:\n\n";
double TotalPrice = 0.0;
for(int i = 0; i < NumPizzas; i++)
{
cout << "Size: " << Pizzas[i].getSizeAsString() << "\n";
OutputFile << "Size: " << Pizzas[i].getSizeAsString() << "\n";
cout << "Curst: " << Pizzas[i].getCrustAsString() << "\n";
OutputFile << "Curst: " << Pizzas[i].getCrustAsString() << "\n";
Pizzas[i].printIngredients(cout);
cout << "\n\nPrice: " << Pizzas[i].getPrice() << "\n\n";
OutputFile << "\n\nPrice: " << Pizzas[i].getPrice() << "\n\n";
TotalPrice += Pizzas[i].getPrice();
}
cout << "\nTotal Price: " << TotalPrice << "\n\n";
OutputFile << "\nTotal Price: " << TotalPrice << "\n\n";
OrderTotal = TotalPrice;
}
// class definition - DO NOT MODIFY ANY CODE IN THIS SECTION
PizzaType::PizzaType()
{
size = SMALL;
crust = THIN;
N_Ingredients = 0;
}
SizeType PizzaType::getSize() const
{
return size;
}
CrustType PizzaType::getCrust() const
{
return crust;
}
int PizzaType::howManyIngredients() const
{
return N_Ingredients;
}
void PizzaType::printIngredients(ostream& out) const
{
for (int idx = 0; idx < N_Ingredients; idx++)
{
out << ingredients[idx] << endl;
}
}
float PizzaType::getPrice() const
{
float price = 5.99f;
switch (size)
{
case MED: price += 1.00; break;
case LARGE: price += 2.50; break;
case SUPER: price += 4.00; break;
}
switch(crust)
{
case THICK: price += 1.00; break;
case TOSSED: price += 1.50; break;
}
if (N_Ingredients > 1)
price += (N_Ingredients - 1); // $1 / ingredient above the first
return price;
}
string PizzaType::getSizeAsString() const
{
switch (size)
{
case SMALL: return "Small";
case MED: return "Medium";
case LARGE: return "Large";
case SUPER: return "Super";
default: return "Bad value";
}
}
string PizzaType::getCrustAsString() const
{
switch(crust)
{
case THIN: return "Thin";
case THICK: return "Thick";
case TOSSED: return "Hand-Tossed";
default: return "Bad value";
}
}
void PizzaType::setSize(SizeType Sz)
{
size = Sz;
}
void PizzaType::setCrust(CrustType Cr)
{
crust = Cr;
}
void PizzaType::setNIngredients(int N)
{
if (N >= 0 && N <= 5)
N_Ingredients = N;
}
void PizzaType::setIngredients()
{
cout << "Enter data for " << N_Ingredients << " ingredients: \n";
for (int idx = 0; idx < N_Ingredients; idx++)
{
cout << '\t' << (idx+1) << ". ";
cin >> ingredients[idx];
}
}
/*
This would modify the class so i cannot do this
void PizzaType::getTotals()
{
ofstream PizzaTotals;
PizzaTotals.open ("PizzaTotals.txt", ios::out | ios::app);
PizzaTotals << Orders << Size << Ingrediants << ;
PizzaTotals.close();
return 0;
*/