rendered paste body/*
CPP 230 - Final Project
by: Joey Burgett
12/3/07
Instructor: Mark Laffoon
*/
// pizza.cpp
//
// This program implements the Pizza class and creates several
// pizza objects to test it out.
#include <iostream>
#include "pizza.h"
using namespace std;
//========================
// Pizza
// The constructor sets the default pizza
// to a small, deep dish, with only cheese.
//========================
Pizza::Pizza()
{
size = SMALL;
type = DEEPDISH;
pepperoniToppings = 0;
cheeseToppings = 1;
}
//==================================
// Accessors and Mutators Follow
//==================================
int Pizza::getPepperoniToppings()
{
return pepperoniToppings;
}
void Pizza::setPepperoniToppings(int numPepperoni)
{
pepperoniToppings=numPepperoni;
}
int Pizza::getCheeseToppings()
{
return cheeseToppings;
}
void Pizza::setCheeseToppings(int numCheese)
{
cheeseToppings=numCheese;
}
int Pizza::getSize()
{
return size;
}
void Pizza::setSize(int newSize)
{
size=newSize;
}
int Pizza::getType()
{
return type;
}
void Pizza::setType(int newType)
{
type=newType;
}
//==================================
// outputDescription
// Prints a textual description of the contents of the pizza.
//==================================
void Pizza::outputDescription()
{
cout << "\nYour Order: ";
switch(size)
{
case 0:
cout << "Small, ";
break;
case 1:
cout << "Medium, ";
break;
case 2:
cout << "Large, ";
break;
}
switch (type)
{
case 0:
cout << "Deep-dish pizza ";
break;
case 1:
cout << "Hand Tossed pizza ";
break;
case 2:
cout << "Pan pizza ";
break;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "with " << cheeseToppings << " cheese and " << pepperoniToppings << " pepperoni toppings...\n";
}
//==================================
// computePrice
// Returns:
// Price of a pizza using the formula:
// Small = $10 + $2 per topping
// Medium = $14 + $2 per topping
// Large = $17 + $2 per topping
//==================================
double Pizza::computePrice()
{
double price;
switch (size)
{
case 0:
price = 10.00;
break;
case 1:
price = 14.00;
break;
case 2:
price = 17.00;
break;
}
return (price + ((cheeseToppings + pepperoniToppings)*2.00));
}
// ======================
// main function
// ======================
int main()
{
// Variable declarations
Pizza cheesy;
Pizza pepperoni;
cheesy.setCheeseToppings(3);
cheesy.setType(HANDTOSSED);
cheesy.outputDescription();
cout << "Price of cheesy: " << cheesy.computePrice() << endl;
pepperoni.setSize(LARGE);
pepperoni.setPepperoniToppings(2);
pepperoni.setType(PAN);
pepperoni.outputDescription();
cout << "Price of pepperoni: " << pepperoni.computePrice() << endl;
cout << endl;
system("PAUSE");
}